Skip to contentSkip to conversation

shared/crypto: Add bt_crypto_sirk

RFC In review Luiz Augusto von Dentz 4 participants 26 messages Mar 7, 2023 – Apr 15, 2023

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

RFC v2 1/12 shared/crypto: Add bt_crypto_sirk

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

This adds bt_crypto_sirk which attempts to generate a unique SIRK using the following steps:

- Generate a hash (k) using the str as input
- Generate a hash (sirk) using vendor, product, version and source as input
- Encrypt sirk using k as LTK with sef function.

---
 src/shared/crypto.c | 40 ++++++++++++++++++++++++++++++++++++++++
 src/shared/crypto.h |  3 +++
 2 files changed, 43 insertions(+)
src/shared/crypto.c +40 -0
index 4cb2ea857ea8..5449621b55ea 100644
@@ -926,3 +926,43 @@ bool bt_crypto_sef(struct bt_crypto *crypto, const uint8_t k[16],
 
 	return true;
 }
+
+/* Generates a SIRK from a string using the following steps:
+ *  - Generate a hash (k) using the str as input
+ *  - Generate a hash (sirk) using vendor, product, version and source as input
+ *  - Encrypt sirk using k as LTK with sef function.
+ */
+bool bt_crypto_sirk(struct bt_crypto *crypto, const char *str, uint16_t vendor,
+			uint16_t product, uint16_t version, uint16_t source,
+			uint8_t sirk[16])
+{
+	struct iovec iov[4];
+	uint8_t k[16];
+	uint8_t sirk_plaintext[16];
+
+	if (!crypto)
+		return false;
+
+	iov[0].iov_base = (void *)str;
+	iov[0].iov_len = strlen(str);
+
+	/* Generate a k using the str as input */
+	if (!bt_crypto_gatt_hash(crypto, iov, 1, k))
+		return false;
+
+	iov[0].iov_base = &vendor;
+	iov[0].iov_len = sizeof(vendor);
+	iov[1].iov_base = &product;
+	iov[1].iov_len = sizeof(product);
+	iov[2].iov_base = &version;
+	iov[2].iov_len = sizeof(version);
+	iov[3].iov_base = &source;
+	iov[3].iov_len = sizeof(source);
+
+	/* Generate a sirk using vendor, product, version and source as input */
+	if (!bt_crypto_gatt_hash(crypto, iov, 4, sirk_plaintext))
+		return false;
+
+	/* Encrypt sirk using k as LTK with sef function */
+	return bt_crypto_sef(crypto, k, sirk_plaintext, sirk);
+}
src/shared/crypto.h +3 -0
index fc1ba0c4feeb..d45308abf90a 100644
@@ -57,3 +57,6 @@ bool bt_crypto_sef(struct bt_crypto *crypto, const uint8_t k[16],
 			const uint8_t sirk[16], uint8_t out[16]);
 bool bt_crypto_sih(struct bt_crypto *crypto, const uint8_t k[16],
 					const uint8_t r[3], uint8_t hash[3]);
+bool bt_crypto_sirk(struct bt_crypto *crypto, const char *str, uint16_t vendor,
+			uint16_t product, uint16_t version, uint16_t source,
+			uint8_t sirk[16]);
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

RFC v2 2/12 shared/ad: Add RSI data type

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

This adds BT_AD_CSIP_RSI advertising data type.

---
 src/shared/ad.h | 1 +
 1 file changed, 1 insertion(+)
src/shared/ad.h +1 -0
index feb712f508cf..b100a6796109 100644
@@ -57,6 +57,7 @@
 #define BT_AD_MESH_PROV			0x29
 #define BT_AD_MESH_DATA			0x2a
 #define BT_AD_MESH_BEACON		0x2b
+#define BT_AD_CSIP_RSI			0x2e
 #define BT_AD_3D_INFO_DATA		0x3d
 #define BT_AD_MANUFACTURER_DATA		0xff
 
Signature · 1 line
2.39.2
author maintainer
#2 lore raw

RFC v2 3/12 doc: Add set-api

In reply to Luiz Augusto von Dentz

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

This adds set-api.rst which documents DeviceSet interface.

---
 doc/set-api.rst | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 doc/set-api.rst
doc/set-api.rst new file +53 -0
new file mode 100644
index 000000000000..c49be1ae0514
@@ -0,0 +1,53 @@
+=====================================
+BlueZ D-Bus DeviceSet API description
+=====================================
+
+
+DeviceSet interface
+===================
+
+Service		org.bluez
+Interface	org.bluez.DeviceSet1
+Object path	[variable prefix]/{hci0,hci1,...}/set_{sirk}
+
+Methods
+=======
+
+**void Connect() [experimental]**
+
+	Connects all **devices** members of the set, each member is
+	connected in sequence as they were added/loaded following the
+	same proceedure as described in **Device1.Connect**.
+
+	Possible errors: org.bluez.Error.NotReady
+			 org.bluez.Error.Failed
+			 org.bluez.Error.InProgress
+			 org.bluez.Error.AlreadyConnected
+
+**void Disconnect() [experimental]**
+
+	Disconnects all **devices** members of the set, each member is
+	disconnected in sequence as they were connected following the
+	same proceedure as described in **Device1.Disconnect**.
+
+	Possible errors: org.bluez.Error.NotConnected
+
+Properties
+==========
+
+**object Adapter [readonly]**
+
+	The object path of the adapter the set belongs to.
+
+**bool AutoConnect [read-write, experimental]**
+
+	Indicates if the **devices** members of the set shall be automatically
+	connected once any of its members is connected.
+
+**array(object) Devices [ready-only, experimental]**
+
+	List of devices objects that are members of the set.
+
+**byte Size [read-only, experimental]**
+
+	Set members size.
Signature · 1 line
2.39.2
author maintainer
#3 lore raw

RFC v2 4/12 device-api: Add Set property

In reply to Luiz Augusto von Dentz

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

This adds Set property so clients are able to identify when a device belongs to a set.

---
 doc/device-api.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)
doc/device-api.txt +10 -0
index 628accb8a572..e4a8d3c5af33 100644
@@ -281,3 +281,13 @@ Properties	string Address [readonly]
 			Example:
 				<Transport Discovery> <Organization Flags...>
 				0x26                   0x01         0x01...
+
+		array{object, dict} Sets [readonly, experimental]
+
+			The object paths of the sets the device belongs to
+			followed by a dictionary which can contain the
+			following:
+
+				byte Rank:
+
+					Rank of the device in the Set.
Signature · 1 line
2.39.2
author maintainer
#4 lore raw

RFC v2 5/12 core: Add initial implementation of DeviceSet interface

In reply to Luiz Augusto von Dentz

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

This adds the initial implementation of DeviceSet interface as documented in doc/set-api.rst.

---
 Makefile.am   |   3 +-
 src/adapter.c |   6 +-
 src/device.c  | 283 +++++++++++++++++++++++++++++++++++++-
 src/device.h  |  11 +-
 src/set.c     | 371 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/set.h     |  20 +++
 6 files changed, 683 insertions(+), 11 deletions(-)
 create mode 100644 src/set.c
 create mode 100644 src/set.h
Makefile.am +2 -1
index 0e8cce249c7d..7b010c8159e9 100644
@@ -326,7 +326,8 @@ src_bluetoothd_SOURCES = $(builtin_sources) \
 			src/eir.h src/eir.c \
 			src/adv_monitor.h src/adv_monitor.c \
 			src/battery.h src/battery.c \
-			src/settings.h src/settings.c
+			src/settings.h src/settings.c \
+			src/set.h src/set.c
 src_bluetoothd_LDADD = lib/libbluetooth-internal.la \
 			gdbus/libgdbus-internal.la \
 			src/libshared-glib.la \
src/adapter.c +3 -3
index 538310c1ddc6..ae0eb364bad5 100644
@@ -4387,8 +4387,8 @@ static void load_ltks(struct btd_adapter *adapter, GSList *keys)
 		if (dev) {
 			device_set_paired(dev, info->bdaddr_type);
 			device_set_bonded(dev, info->bdaddr_type);
-			device_set_ltk_enc_size(dev, info->enc_size);
-			device_set_ltk_enc_size(dev, info->enc_size);
+			device_set_ltk(dev, info->val, info->central,
+						info->enc_size);
 		}
 	}
 
@@ -8657,7 +8657,7 @@ static void new_long_term_key_callback(uint16_t index, uint16_t length,
 		device_set_bonded(device, addr->type);
 	}
 
-	device_set_ltk_enc_size(device, ev->key.enc_size);
+	device_set_ltk(device, ev->key.val, ev->key.central, ev->key.enc_size);
 
 	bonding_complete(adapter, &addr->bdaddr, addr->type, 0);
 }
src/device.c +278 -5

384 lines not on this page · raw message

src/device.h +9 -2
index 9e81fda9e948..96347ff229cc 100644
@@ -128,8 +128,10 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type,
 								bool *remove);
 void device_request_disconnect(struct btd_device *device, DBusMessage *msg);
 bool device_is_disconnecting(struct btd_device *device);
-void device_set_ltk_enc_size(struct btd_device *device, uint8_t enc_size);
-
+void device_set_ltk(struct btd_device *device, const uint8_t val[16],
+				bool central, uint8_t enc_size);
+bool btd_device_add_set(struct btd_device *device, bool encrypted,
+				uint8_t sirk[16], uint8_t size, uint8_t rank);
 void device_store_svc_chng_ccc(struct btd_device *device, uint8_t bdaddr_type,
 								uint16_t value);
 void device_load_svc_chng_ccc(struct btd_device *device, uint16_t *ccc_le,
@@ -188,3 +190,8 @@ void btd_device_cleanup(void);
 
 void btd_device_set_volume(struct btd_device *dev, int8_t volume);
 int8_t btd_device_get_volume(struct btd_device *dev);
+
+typedef void (*bt_device_ad_func_t)(void *data, void *user_data);
+
+void btd_device_foreach_ad(struct btd_device *dev, bt_device_ad_func_t func,
+							void *data);
src/set.c new file +371 -0

371 lines not on this page · raw message

src/set.h new file +20 -0
new file mode 100644
index 000000000000..67177e8c7946
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2023  Intel Corporation
+ *
+ *
+ */
+
+#define BTD_DEVICE_SET_INTERFACE	"org.bluez.DeviceSet1"
+
+struct btd_device_set;
+
+struct btd_device_set *btd_set_add_device(struct btd_device *device,
+						uint8_t *ltk, uint8_t sirk[16],
+						uint8_t size);
+bool btd_set_remove_device(struct btd_device_set *set,
+						struct btd_device *device);
+const char *btd_set_get_path(struct btd_device_set *set);
Signature · 1 line
2.39.2
author maintainer
#5 lore raw

RFC v2 6/12 core: Check if device has RSI

In reply to Luiz Augusto von Dentz

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

This checks if device is advertising an RSI and if so disregards if it is not discoverable since other members can be.

---
 src/adapter.c | 4 ++--
 src/eir.c     | 3 +++
 src/eir.h     | 2 ++
 3 files changed, 7 insertions(+), 2 deletions(-)
src/adapter.c +2 -2
index ae0eb364bad5..7947160a6c5c 100644
@@ -7122,7 +7122,7 @@ void btd_adapter_update_found_device(struct btd_adapter *adapter,
 
 	dev = btd_adapter_find_device(adapter, bdaddr, bdaddr_type);
 	if (!dev) {
-		if (!discoverable && !monitoring) {
+		if (!discoverable && !monitoring && !eir_data.rsi) {
 			eir_data_free(&eir_data);
 			return;
 		}
@@ -7169,7 +7169,7 @@ void btd_adapter_update_found_device(struct btd_adapter *adapter,
 	/* If there is no matched Adv monitors, don't continue if not
 	 * discoverable or if active discovery filter don't match.
 	 */
-	if (!monitoring && (!discoverable ||
+	if (!eir_data.rsi && !monitoring && (!discoverable ||
 		(adapter->filtered_discovery && !is_filter_match(
 				adapter->discovery_list, &eir_data, rssi)))) {
 		eir_data_free(&eir_data);
src/eir.c +3 -0
index 2f9ee036ffd5..52152c0d7f52 100644
@@ -236,6 +236,9 @@ static void eir_parse_data(struct eir_data *eir, uint8_t type,
 	memcpy(ad->data, data, len);
 
 	eir->data_list = g_slist_append(eir->data_list, ad);
+
+	if (type == EIR_CSIP_RSI)
+		eir->rsi = true;
 }
 
 void eir_parse(struct eir_data *eir, const uint8_t *eir_data, uint8_t eir_len)
src/eir.h +2 -0
index 6154e23ec266..a4bf5fbd33f3 100644
@@ -37,6 +37,7 @@
 #define EIR_SVC_DATA32              0x20  /* LE: Service data, 32-bit UUID */
 #define EIR_SVC_DATA128             0x21  /* LE: Service data, 128-bit UUID */
 #define EIR_TRANSPORT_DISCOVERY     0x26  /* Transport Discovery Service */
+#define EIR_CSIP_RSI                0x2e  /* Resolvable Set Identifier */
 #define EIR_MANUFACTURER_DATA       0xFF  /* Manufacturer Specific Data */
 
 /* Flags Descriptions */
@@ -76,6 +77,7 @@ struct eir_data {
 	uint32_t class;
 	uint16_t appearance;
 	bool name_complete;
+	bool rsi;
 	int8_t tx_power;
 	uint8_t *hash;
 	uint8_t *randomizer;
Signature · 1 line
2.39.2
author maintainer
#6 lore raw

RFC v2 7/12 main.conf: Add CSIP profile configurable options

In reply to Luiz Augusto von Dentz

From: Sathish Narasimman <[email protected]>

This introduces option to configure main.conf that can be used to configure co-ordinated set identification profile.

---
 src/btd.h     |   9 ++++
 src/main.c    | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/main.conf |  25 ++++++++++
 3 files changed, 158 insertions(+)
src/btd.h +9 -0
index 42cffcde43ca..70051c71c7c1 100644
@@ -92,6 +92,13 @@ struct btd_defaults {
 	struct btd_le_defaults le;
 };
 
+struct btd_csis {
+	bool    encrypt;
+	uint8_t sirk[16];
+	uint8_t size;
+	uint8_t rank;
+};
+
 struct btd_avdtp_opts {
 	uint8_t  session_mode;
 	uint8_t  stream_mode;
@@ -142,6 +149,8 @@ struct btd_opts {
 	enum jw_repairing_t jw_repairing;
 
 	struct btd_advmon_opts	advmon;
+
+	struct btd_csis csis;
 };
 
 extern struct btd_opts btd_opts;
src/main.c +124 -0

165 lines not on this page · raw message

src/main.conf +25 -0
index f187c9aaa482..11172c9dd7c6 100644
@@ -258,6 +258,31 @@
 # Default to 3
 #Channels = 3
 
+[CSIS]
+# SIRK - Set Identification Resolution Key which is common for all the
+# sets. They SIRK key is used to identify its sets. This can be any
+# 128 bit value or a string value (e.g. product name) which is then hashed.
+# Possible Values:
+# 16 byte hexadecimal value: 861FAE703ED681F0C50B34155B6434FB
+# String value: "My Product Name"
+# Defaults to none
+#SIRK =
+
+# SIRK Encryption
+# Possible values:
+# yes: Encrypt SIRK when read
+# no: Do not encrypt SIRK when read. (plaintext)
+# Defaults to yes
+#Encryption = yes
+
+# Total no of sets belongs to this Profile
+# Defaults to 0
+#Size = 0
+
+# Rank for the device
+# Defaults to 0
+#Rank = 0
+
 [AVDTP]
 # AVDTP L2CAP Signalling Channel Mode.
 # Possible values:
Signature · 1 line
2.39.2
author maintainer
#7 lore raw

RFC v2 8/12 shared/csip: Add initial code for handling CSIP

In reply to Luiz Augusto von Dentz

From: Sathish Narasimman <[email protected]>

This adds initial code for Coordinated Set Identification Profile.

---
 Makefile.am       |   1 +
 src/shared/csip.c | 866 ++++++++++++++++++++++++++++++++++++++++++++++
 src/shared/csip.h |  67 ++++
 3 files changed, 934 insertions(+)
 create mode 100644 src/shared/csip.c
 create mode 100644 src/shared/csip.h
Makefile.am +1 -0
index 7b010c8159e9..7ded3ba75138 100644
@@ -233,6 +233,7 @@ shared_sources = src/shared/io.h src/shared/timeout.h \
 			src/shared/bap.h src/shared/bap.c src/shared/ascs.h \
 			src/shared/mcs.h src/shared/mcp.h src/shared/mcp.c \
 			src/shared/vcp.c src/shared/vcp.h \
+			src/shared/csip.c src/shared/csip.h \
 			src/shared/lc3.h src/shared/tty.h
 
 if READLINE
src/shared/csip.c new file +866 -0

866 lines not on this page · raw message

src/shared/csip.h new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
2.39.2
author maintainer
#8 lore raw

RFC v2 9/12 profiles: Add initial code for csip plugin

In reply to Luiz Augusto von Dentz

From: Sathish Narasimman <[email protected]>

This adds initial code for csip plugin which handles Coordinated set identification Profile and Coordinated Set Identification Service.

---
 Makefile.plugins      |   5 +
 configure.ac          |   4 +
 profiles/audio/csip.c | 363 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 372 insertions(+)
 create mode 100644 profiles/audio/csip.c
Makefile.plugins +5 -0
index 20cac384ef44..0f119e8714b7 100644
@@ -131,3 +131,8 @@ if VCP
 builtin_modules += vcp
 builtin_sources += profiles/audio/vcp.c
 endif
+
+if CSIP
+builtin_modules += csip
+builtin_sources += profiles/audio/csip.c
+endif
configure.ac +4 -0
index 515cdf1461eb..6f890110f554 100644
@@ -207,6 +207,10 @@ AC_ARG_ENABLE(vcp, AS_HELP_STRING([--disable-vcp],
 		[disable VCP profile]), [enable_vcp=${enableval}])
 AM_CONDITIONAL(VCP, test "${enable_vcp}" != "no")
 
+AC_ARG_ENABLE(csip, AS_HELP_STRING([--disable-csip],
+		[disable CSIP profile]), [enable_csip=${enableval}])
+AM_CONDITIONAL(CSIP, test "${enable_csip}" != "no")
+
 AC_ARG_ENABLE(tools, AS_HELP_STRING([--disable-tools],
 		[disable Bluetooth tools]), [enable_tools=${enableval}])
 AM_CONDITIONAL(TOOLS, test "${enable_tools}" != "no")
profiles/audio/csip.c new file +363 -0

363 lines not on this page · raw message

Signature · 1 line
2.39.2
author maintainer
#9 lore raw

RFC v2 10/12 tools: Add support to generate RSI using SIRK

In reply to Luiz Augusto von Dentz

From: Sathish Narasimman <[email protected]>

The patch helps to generate Resolvable set identifier adv data. which can be used as ADV data during advertisement.
It will be used to identify the device as part of setmember for Coordinated set identification profile.
Example:
$<path to advtest/>advtest -i "761FAE703ED681F0C50B34155B6434FB"
SIRK: 761FAE703ED681F0C50B34155B6434FB
RSI: 0x71 0xcb 0xbc 0x7e 0x01 0x84

    Random: bccb71
    Hash:   84017e
---
 tools/advtest.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 78 insertions(+), 2 deletions(-)
tools/advtest.c +78 -2
index de036e783325..9ef69ed5124a 100644
@@ -13,6 +13,13 @@
 #include <config.h>
 #endif
 
+#include <stdlib.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
 #include <getopt.h>
 
 #include "lib/bluetooth.h"
@@ -32,6 +39,9 @@
 			"\xe1\x23\x99\xc1\xca\x9a\xc3\x31"
 #define SCAN_IRK	"\xfa\x73\x09\x11\x3f\x03\x37\x0f" \
 			"\xf4\xf9\x93\x1e\xf9\xa3\x63\xa6"
+#ifndef MIN
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
+#endif
 
 static struct mgmt *mgmt;
 static uint16_t index1 = MGMT_INDEX_NONE;
@@ -43,13 +53,73 @@ static struct bt_hci *scan_dev;
 
 static void print_rpa(const uint8_t addr[6])
 {
-	printf("  Address:  %02x:%02x:%02x:%02x:%02x:%02x\n",
+	printf("  RSI:\t0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
 					addr[5], addr[4], addr[3],
 					addr[2], addr[1], addr[0]);
 	printf("    Random: %02x%02x%02x\n", addr[3], addr[4], addr[5]);
 	printf("    Hash:   %02x%02x%02x\n", addr[0], addr[1], addr[2]);
 }
 
+static size_t hex2bin(const char *hexstr, uint8_t *buf, size_t buflen)
+{
+	size_t i, len;
+
+	len = MIN((strlen(hexstr) / 2), buflen);
+	memset(buf, 0, len);
+
+	for (i = 0; i < len; i++)
+		if (sscanf(hexstr + (i * 2), "%02hhX", &buf[i]) != 1)
+			continue;
+
+
+	return len;
+}
+
+static bool get_random_bytes(void *buf, size_t num_bytes)
+{
+	ssize_t len;
+	int fd;
+
+	fd = open("/dev/urandom", O_RDONLY);
+	if (fd < 0)
+		return false;
+
+	len = read(fd, buf, num_bytes);
+
+	close(fd);
+
+	if (len < 0)
+		return false;
+
+	return true;
+}
+
+static void generate_rsi(char *val)
+{
+	uint8_t sirk[16], hash[3];
+	uint8_t  rsi[6] = {0};
+
+	hex2bin(val, sirk, sizeof(sirk));
+
+	get_random_bytes(&rsi[3], 3);
+
+	rsi[5] &= 0x3f; /* Clear 2 msb */
+	rsi[5] |= 0x40; /* Set 2nd msb */
+
+	crypto = bt_crypto_new();
+	if (!crypto) {
+		fprintf(stderr, "Failed to open crypto interface\n");
+		mainloop_exit_failure();
+		return;
+	}
+
+	bt_crypto_ah(crypto, sirk, rsi + 3, hash);
+	memcpy(rsi, hash, 3);
+
+	print_rpa(rsi);
+}
+
+
 static void scan_le_adv_report(const void *data, uint8_t size,
 							void *user_data)
 {
@@ -351,9 +421,11 @@ static void usage(void)
 	printf("\tadvtest [options]\n");
 	printf("options:\n"
 		"\t-h, --help             Show help options\n");
+	printf(" \t-i  <128bit SIRK>,     Generate RSI ADV Data\n");
 }
 
 static const struct option main_options[] = {
+	{ "hash",   no_argument,       NULL, 'i' },
 	{ "version",   no_argument,       NULL, 'v' },
 	{ "help",      no_argument,       NULL, 'h' },
 	{ }
@@ -366,11 +438,15 @@ int main(int argc ,char *argv[])
 	for (;;) {
 		int opt;
 
-		opt = getopt_long(argc, argv, "vh", main_options, NULL);
+		opt = getopt_long(argc, argv, "i:vh", main_options, NULL);
 		if (opt < 0)
 			break;
 
 		switch (opt) {
+		case 'i':
+			printf("SIRK: %s\n", optarg);
+			generate_rsi(optarg);
+			return EXIT_SUCCESS;
 		case 'v':
 			printf("%s\n", VERSION);
 			return EXIT_SUCCESS;
Signature · 1 line
2.39.2
author maintainer
#10 lore raw

RFC v2 11/12 client: Add support for DeviceSet proxy

In reply to Luiz Augusto von Dentz

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

---
 client/main.c | 113 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 103 insertions(+), 10 deletions(-)
client/main.c +103 -10
index e5cf1e203ed1..e4a39896b2c6 100644
@@ -51,6 +51,7 @@ struct adapter {
 	GDBusProxy *ad_proxy;
 	GDBusProxy *adv_monitor_proxy;
 	GList *devices;
+	GList *sets;
 };
 
 static struct adapter *default_ctrl;
@@ -232,7 +233,7 @@ static void print_experimental(GDBusProxy *proxy)
 	}
 }
 
-static gboolean device_is_child(GDBusProxy *device, GDBusProxy *parent)
+static gboolean proxy_is_child(GDBusProxy *device, GDBusProxy *parent)
 {
 	DBusMessageIter iter;
 	const char *adapter, *path;
@@ -269,14 +270,14 @@ static gboolean service_is_child(GDBusProxy *service)
 					"org.bluez.Device1") != NULL;
 }
 
-static struct adapter *find_parent(GDBusProxy *device)
+static struct adapter *find_parent(GDBusProxy *proxy)
 {
 	GList *list;
 
 	for (list = g_list_first(ctrl_list); list; list = g_list_next(list)) {
 		struct adapter *adapter = list->data;
 
-		if (device_is_child(device, adapter->proxy) == TRUE)
+		if (proxy_is_child(proxy, adapter->proxy) == TRUE)
 			return adapter;
 	}
 	return NULL;
@@ -399,6 +400,27 @@ static void admon_manager_added(GDBusProxy *proxy)
 	adv_monitor_register_app(dbus_conn);
 }
 
+static void print_set(GDBusProxy *proxy, const char *description)
+{
+	bt_shell_printf("%s%s%sDeviceSet %s\n",
+				description ? "[" : "",
+				description ? : "",
+				description ? "] " : "",
+				g_dbus_proxy_get_path(proxy));
+}
+
+static void set_added(GDBusProxy *proxy)
+{
+	struct adapter *adapter = find_parent(proxy);
+
+	if (!adapter)
+		return;
+
+	adapter->sets = g_list_append(adapter->sets, proxy);
+	print_set(proxy, COLORED_NEW);
+	bt_shell_set_env(g_dbus_proxy_get_path(proxy), proxy);
+}
+
 static void proxy_added(GDBusProxy *proxy, void *user_data)
 {
 	const char *interface;
@@ -434,6 +456,8 @@ static void proxy_added(GDBusProxy *proxy, void *user_data)
 	} else if (!strcmp(interface,
 				"org.bluez.AdvertisementMonitorManager1")) {
 		admon_manager_added(proxy);
+	} else if (!strcmp(interface, "org.bluez.DeviceSet1")) {
+		set_added(proxy);
 	}
 }
 
@@ -484,6 +508,7 @@ static void adapter_removed(GDBusProxy *proxy)
 
 			ctrl_list = g_list_remove_link(ctrl_list, ll);
 			g_list_free(adapter->devices);
+			g_list_free(adapter->sets);
 			g_free(adapter);
 			g_list_free(ll);
 			return;
@@ -491,6 +516,19 @@ static void adapter_removed(GDBusProxy *proxy)
 	}
 }
 
+static void set_removed(GDBusProxy *proxy)
+{
+	struct adapter *adapter = find_parent(proxy);
+
+	if (!adapter)
+		return;
+
+	adapter->sets = g_list_remove(adapter->sets, proxy);
+
+	print_set(proxy, COLORED_DEL);
+	bt_shell_set_env(g_dbus_proxy_get_path(proxy), NULL);
+}
+
 static void proxy_removed(GDBusProxy *proxy, void *user_data)
 {
 	const char *interface;
@@ -531,6 +569,8 @@ static void proxy_removed(GDBusProxy *proxy, void *user_data)
 	} else if (!strcmp(interface,
 			"org.bluez.AdvertisementMonitorManager1")) {
 		adv_monitor_remove_manager(dbus_conn);
+	} else if (!strcmp(interface, "org.bluez.DeviceSet1")) {
+		set_removed(proxy);
 	}
 }
 
@@ -557,7 +597,7 @@ static void property_changed(GDBusProxy *proxy, const char *name,
 	interface = g_dbus_proxy_get_interface(proxy);
 
 	if (!strcmp(interface, "org.bluez.Device1")) {
-		if (default_ctrl && device_is_child(proxy,
+		if (default_ctrl && proxy_is_child(proxy,
 					default_ctrl->proxy) == TRUE) {
 			DBusMessageIter addr_iter;
 			char *str;
@@ -1559,6 +1599,39 @@ static struct GDBusProxy *find_device(int argc, char *argv[])
 	return proxy;
 }
 
+static struct GDBusProxy *find_set(int argc, char *argv[])
+{
+	GDBusProxy *proxy;
+
+	if (check_default_ctrl() == FALSE)
+		return NULL;
+
+	proxy = find_proxies_by_path(default_ctrl->sets, argv[1]);
+	if (!proxy) {
+		bt_shell_printf("DeviceSet %s not available\n", argv[1]);
+		return NULL;
+	}
+
+	return proxy;
+}
+
+static void cmd_set_info(int argc, char *argv[])
+{
+	GDBusProxy *proxy;
+
+	proxy = find_set(argc, argv);
+	if (!proxy)
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+
+	bt_shell_printf("DeviceSet %s\n", g_dbus_proxy_get_path(proxy));
+
+	print_property(proxy, "AutoConnect");
+	print_property(proxy, "Devices");
+	print_property(proxy, "Size");
+
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
 static void cmd_info(int argc, char *argv[])
 {
 	GDBusProxy *proxy;
@@ -1568,7 +1641,7 @@ static void cmd_info(int argc, char *argv[])
 
 	proxy = find_device(argc, argv);
 	if (!proxy)
-		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+		return cmd_set_info(argc, argv);
 
 	if (g_dbus_proxy_get_property(proxy, "Address", &iter) == FALSE)
 		return bt_shell_noninteractive_quit(EXIT_FAILURE);
@@ -1605,6 +1678,7 @@ static void cmd_info(int argc, char *argv[])
 	print_property(proxy, "TxPower");
 	print_property(proxy, "AdvertisingFlags");
 	print_property(proxy, "AdvertisingData");
+	print_property(proxy, "Sets");
 
 	battery_proxy = find_proxies_by_path(battery_proxies,
 					g_dbus_proxy_get_path(proxy));
@@ -2298,11 +2372,13 @@ static char *generic_generator(const char *text, int state,
 
 		index++;
 
-		if (g_dbus_proxy_get_property(proxy, property, &iter) == FALSE)
+		if (!property)
+			str = g_dbus_proxy_get_path(proxy);
+		else if (g_dbus_proxy_get_property(proxy, property, &iter))
+			dbus_message_iter_get_basic(&iter, &str);
+		else
 			continue;
 
-		dbus_message_iter_get_basic(&iter, &str);
-
 		if (!strncasecmp(str, text, len))
 			return strdup(str);
 	}
@@ -2348,6 +2424,23 @@ static char *dev_generator(const char *text, int state)
 			default_ctrl ? default_ctrl->devices : NULL, "Address");
 }
 
+static char *set_generator(const char *text, int state)
+{
+	return generic_generator(text, state,
+			default_ctrl ? default_ctrl->sets : NULL, NULL);
+}
+
+static char *dev_set_generator(const char *text, int state)
+{
+	char *str;
+
+	str = dev_generator(text, state);
+	if (str)
+		return str;
+
+	return set_generator(text, state);
+}
+
 static char *attribute_generator(const char *text, int state)
 {
 	return gatt_attribute_generator(text, state);
@@ -2965,8 +3058,8 @@ static const struct bt_shell_menu main_menu = {
 	{ "set-alias",    "<alias>",  cmd_set_alias, "Set device alias" },
 	{ "scan",         "<on/off/bredr/le>", cmd_scan,
 				"Scan for devices", scan_generator },
-	{ "info",         "[dev]",    cmd_info, "Device information",
-							dev_generator },
+	{ "info",         "[dev/set]",    cmd_info, "Device/Set information",
+							dev_set_generator },
 	{ "pair",         "[dev]",    cmd_pair, "Pair with device",
 							dev_generator },
 	{ "cancel-pairing",  "[dev]",    cmd_cancel_pairing,
Signature · 1 line
2.39.2
author maintainer
#11 lore raw

RFC v2 12/12 client: Use AdvertisingFlags when available

In reply to Luiz Augusto von Dentz

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

This prints devices not discoverable in grey so the user are able to distict when for example set members are actually visible.

---
 client/main.c | 79 +++++++++++++++++++++++++++++++++++----------------
 1 file changed, 55 insertions(+), 24 deletions(-)
client/main.c +55 -24
index e4a39896b2c6..79895015d6a6 100644
@@ -24,6 +24,7 @@
 
 #include "src/shared/shell.h"
 #include "src/shared/util.h"
+#include "src/shared/ad.h"
 #include "gdbus/gdbus.h"
 #include "print.h"
 #include "agent.h"
@@ -143,10 +144,32 @@ static void print_adapter(GDBusProxy *proxy, const char *description)
 
 }
 
+#define	DISTANCE_VAL_INVALID	0x7FFF
+
+static struct set_discovery_filter_args {
+	char *transport;
+	char *pattern;
+	dbus_uint16_t rssi;
+	dbus_int16_t pathloss;
+	char **uuids;
+	size_t uuids_len;
+	dbus_bool_t duplicate;
+	dbus_bool_t discoverable;
+	bool set;
+	bool active;
+	unsigned int timeout;
+} filter = {
+	.rssi = DISTANCE_VAL_INVALID,
+	.pathloss = DISTANCE_VAL_INVALID,
+	.set = true,
+};
+
 static void print_device(GDBusProxy *proxy, const char *description)
 {
 	DBusMessageIter iter;
 	const char *address, *name;
+	uint8_t *flags;
+	int flags_len = 0;
 
 	if (g_dbus_proxy_get_property(proxy, "Address", &iter) == FALSE)
 		return;
@@ -158,11 +181,39 @@ static void print_device(GDBusProxy *proxy, const char *description)
 	else
 		name = "<unknown>";
 
+	if (g_dbus_proxy_get_property(proxy, "AdvertisingFlags", &iter)) {
+		DBusMessageIter array;
+
+		dbus_message_iter_recurse(&iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &flags, &flags_len);
+	}
+
+	if (!flags_len)
+		goto done;
+
+	if (!(flags[0] & (BT_AD_FLAG_LIMITED | BT_AD_FLAG_GENERAL))) {
+		/* Only print hidden/non-discoverable if filter.discoverable is
+		 * not set.
+		 */
+		if (filter.discoverable)
+			return;
+
+		bt_shell_printf("%s%s%s" COLOR_BOLDGRAY "Device %s %s"
+					COLOR_OFF "\n",
+					description ? "[" : "",
+					description ? : "",
+					description ? "] " : "",
+					address, name);
+
+		return;
+	}
+
+done:
 	bt_shell_printf("%s%s%sDevice %s %s\n",
-				description ? "[" : "",
-				description ? : "",
-				description ? "] " : "",
-				address, name);
+					description ? "[" : "",
+					description ? : "",
+					description ? "] " : "",
+					address, name);
 }
 
 static void print_uuid(const char *label, const char *uuid)
@@ -1133,26 +1184,6 @@ static void cmd_default_agent(int argc, char *argv[])
 	agent_default(dbus_conn, agent_manager);
 }
 
-#define	DISTANCE_VAL_INVALID	0x7FFF
-
-static struct set_discovery_filter_args {
-	char *transport;
-	char *pattern;
-	dbus_uint16_t rssi;
-	dbus_int16_t pathloss;
-	char **uuids;
-	size_t uuids_len;
-	dbus_bool_t duplicate;
-	dbus_bool_t discoverable;
-	bool set;
-	bool active;
-	unsigned int timeout;
-} filter = {
-	.rssi = DISTANCE_VAL_INVALID,
-	.pathloss = DISTANCE_VAL_INVALID,
-	.set = true,
-};
-
 static void start_discovery_reply(DBusMessage *message, void *user_data)
 {
 	dbus_bool_t enable = GPOINTER_TO_UINT(user_data);
Signature · 1 line
2.39.2
#12 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=727653

---Test result---

Test Summary:

CheckPatch                    FAIL      8.44 seconds
GitLint                       PASS      3.89 seconds
BuildEll                      PASS      32.44 seconds
BluezMake                     PASS      970.60 seconds
MakeCheck                     PASS      11.92 seconds
MakeDistcheck                 PASS      160.99 seconds
CheckValgrind                 PASS      263.34 seconds
CheckSmatch                   WARNING   363.40 seconds
bluezmakeextell               PASS      111.16 seconds
IncrementalBuild              PASS      9602.60 seconds
ScanBuild                     PASS      1222.18 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[RFC,v2,01/12] shared/crypto: Add bt_crypto_sirk
WARNING:COMMIT_LOG_LONG_LINE: Possible unwrapped commit description (prefer a maximum 75 chars per line) #84:
- Generate a hash (sirk) using vendor, product, version and source as input

/github/workspace/src/src/13164836.patch total: 0 errors, 1 warnings, 49 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13164836.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

[RFC,v2,07/12] main.conf: Add CSIP profile configurable options WARNING:STATIC_CONST_CHAR_ARRAY: static const char * array should probably be static const char * const #145: FILE: src/main.c:153:
+static const char *csip_options[] = {

/github/workspace/src/src/13164842.patch total: 0 errors, 1 warnings, 217 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13164842.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

[RFC,v2,08/12] shared/csip: Add initial code for handling CSIP WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #998: FILE: src/shared/csip.h:16:
+#define __packed __attribute__((packed))

/github/workspace/src/src/13164843.patch total: 0 errors, 1 warnings, 940 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13164843.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
src/shared/crypto.c:271:21: warning: Variable length array is used.src/shared/crypto.c:272:23: warning: Variable length array is used.src/shared/crypto.c:271:21: warning: Variable length array is used.src/shared/crypto.c:272:23: warning: Variable length array is used.src/shared/crypto.c:271:21: warning: Variable length array is used.src/shared/crypto.c:272:23: warning: Variable length array is used.

---
Regards,
Linux Bluetooth

#13 lore raw
In reply to Luiz Augusto von Dentz
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

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

Quoted 10 lines · On Tue, 7 Mar 2023 14:24:11 -0800 you wrote:

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

This adds bt_crypto_sirk which attempts to generate a unique SIRK using the following steps:

- Generate a hash (k) using the str as input
- Generate a hash (sirk) using vendor, product, version and source as input
- Encrypt sirk using k as LTK with sef function.

[...]

Here is the summary with links:
- [RFC,v2,01/12] shared/crypto: Add bt_crypto_sirk

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c1dd94cc7f81
  - [RFC,v2,02/12] shared/ad: Add RSI data type
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c2e99aefd337
  - [RFC,v2,03/12] doc: Add set-api
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=6477522e92e3
  - [RFC,v2,04/12] device-api: Add Set property
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5bac4cddb191
  - [RFC,v2,05/12] core: Add initial implementation of DeviceSet interface
    (no matching commit)
  - [RFC,v2,06/12] core: Check if device has RSI
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f95ffcc8b1fe
  - [RFC,v2,07/12] main.conf: Add CSIP profile configurable options
    (no matching commit)
  - [RFC,v2,08/12] shared/csip: Add initial code for handling CSIP
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d297a03b7a61
  - [RFC,v2,09/12] profiles: Add initial code for csip plugin
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9e1eb0a62b3f
  - [RFC,v2,10/12] tools: Add support to generate RSI using SIRK
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c446a64d461b
  - [RFC,v2,11/12] client: Add support for DeviceSet proxy
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=373bafc34ce6
  - [RFC,v2,12/12] client: Use AdvertisingFlags when available
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=815f779aa8e4

You are awesome, thank you!

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

Hi Pauli, Frederic,

Quoted 44 lines · On Fri, Mar 10, 2023 at 4:40 PM <[email protected]> wrote:

Hello:

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

Quoted 10 lines · On Tue, 7 Mar 2023 14:24:11 -0800 you wrote:

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

This adds bt_crypto_sirk which attempts to generate a unique SIRK using the following steps:

- Generate a hash (k) using the str as input
- Generate a hash (sirk) using vendor, product, version and source as input
- Encrypt sirk using k as LTK with sef function.

[...]

Here is the summary with links:
- [RFC,v2,01/12] shared/crypto: Add bt_crypto_sirk

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c1dd94cc7f81
  - [RFC,v2,02/12] shared/ad: Add RSI data type
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c2e99aefd337
  - [RFC,v2,03/12] doc: Add set-api
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=6477522e92e3
  - [RFC,v2,04/12] device-api: Add Set property
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5bac4cddb191
  - [RFC,v2,05/12] core: Add initial implementation of DeviceSet interface
    (no matching commit)
  - [RFC,v2,06/12] core: Check if device has RSI
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f95ffcc8b1fe
  - [RFC,v2,07/12] main.conf: Add CSIP profile configurable options
    (no matching commit)
  - [RFC,v2,08/12] shared/csip: Add initial code for handling CSIP
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d297a03b7a61
  - [RFC,v2,09/12] profiles: Add initial code for csip plugin
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9e1eb0a62b3f
  - [RFC,v2,10/12] tools: Add support to generate RSI using SIRK
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c446a64d461b
  - [RFC,v2,11/12] client: Add support for DeviceSet proxy
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=373bafc34ce6
  - [RFC,v2,12/12] client: Use AdvertisingFlags when available
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=815f779aa8e4
Quoted 4 lines

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Let me know if you guys are happy with this interface to detect Coordinated Sets, it still experimental so we can experiment with it until we think it is stable, regarding the implementation of the transports one major difference here is that we will need to encode left and right separately, not sure how hard it is to do that in pipewire?

Quoted 1 line
Signature · 1 line
Luiz Augusto von Dentz
#15 lore raw

Hi,

su, 2023-03-12 kello 22:36 -0700, Luiz Augusto von Dentz kirjoitti:

Quoted 52 lines

Hi Pauli, Frederic,

Quoted 44 lines · On Fri, Mar 10, 2023 at 4:40 PM <[email protected]> wrote:

Hello:

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

Quoted 10 lines · On Tue, 7 Mar 2023 14:24:11 -0800 you wrote:

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

This adds bt_crypto_sirk which attempts to generate a unique SIRK using the following steps:

- Generate a hash (k) using the str as input
- Generate a hash (sirk) using vendor, product, version and source as input
- Encrypt sirk using k as LTK with sef function.

[...]

Here is the summary with links:
- [RFC,v2,01/12] shared/crypto: Add bt_crypto_sirk

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c1dd94cc7f81
  - [RFC,v2,02/12] shared/ad: Add RSI data type
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c2e99aefd337
  - [RFC,v2,03/12] doc: Add set-api
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=6477522e92e3
  - [RFC,v2,04/12] device-api: Add Set property
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5bac4cddb191
  - [RFC,v2,05/12] core: Add initial implementation of DeviceSet interface
    (no matching commit)
  - [RFC,v2,06/12] core: Check if device has RSI
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f95ffcc8b1fe
  - [RFC,v2,07/12] main.conf: Add CSIP profile configurable options
    (no matching commit)
  - [RFC,v2,08/12] shared/csip: Add initial code for handling CSIP
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d297a03b7a61
  - [RFC,v2,09/12] profiles: Add initial code for csip plugin
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9e1eb0a62b3f
  - [RFC,v2,10/12] tools: Add support to generate RSI using SIRK
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c446a64d461b
  - [RFC,v2,11/12] client: Add support for DeviceSet proxy
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=373bafc34ce6
  - [RFC,v2,12/12] client: Use AdvertisingFlags when available
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=815f779aa8e4
Quoted 4 lines

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Quoted 6 lines

Let me know if you guys are happy with this interface to detect Coordinated Sets, it still experimental so we can experiment with it until we think it is stable, regarding the implementation of the transports one major difference here is that we will need to encode left and right separately, not sure how hard it is to do that in pipewire?

As far as the device set DBus interface is concerned, it seems to work fine for me currently (in wip implementation for PW [0]). Don't right now see something that would need to be added/changed in it.

Channel splitting/merging is generally easy in PW. How the playback synchronization is going to work on socket level may determine a bit at what level in PW it is convenient to do though.

---

Laundry list for PW related to this:

* How to do TX syncronization properly with the ISO sockets needs still some thinking. I have some wip patches [2] that add the timestamps and other socket API that provide timing information to allow synchronization to the Number of Completed packets events. Corresponding Pipewire implementation [3] rate matches to keep the time difference between those events and our audio reference time fixed at e.g. 25ms (2 packets in controller). Not really clear yet if this is a right thing to do to help the controller send packets at the right time.

Here I see LE Read ISO TX Sync with Intel AX210 returning only zero values in Command Complete in btmon for running CIS, so that command doesn't seem to help here.

* BlueZ doesn't seem to pass on the PAC audio location it reads via read_sink/source_pac_loc, probably very easy to fix.

* The CIS in a CIG cannot be started one by one, or connected to same destination. The kernel appears to wait until all CIS sockets in same CIG go to connect state before proceeding to create CIS. The spec does not seem to require this (I have some pre-rfc patches to make it more flexible [1].)

* PW currently does transport acquires synchronously and fails because of that with multiple CIS, but it probably should do them async.

[0] https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1564
[1] https://github.com/pv/linux/commits/iso-fix-multicis
[2] https://github.com/pv/linux/commits/iso-timestamp
[3] https://gitlab.freedesktop.org/pvir/pipewire/-/commits/iso-timestamp-test

Signature · 1 line
Pauli Virtanen
author maintainer
#16 lore raw

Hi Pauli,

Quoted 76 lines · Pauli Virtanen

Hi,

su, 2023-03-12 kello 22:36 -0700, Luiz Augusto von Dentz kirjoitti:

Quoted 52 lines

Hi Pauli, Frederic,

Quoted 44 lines · On Fri, Mar 10, 2023 at 4:40 PM <[email protected]> wrote:

Hello:

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

Quoted 10 lines · On Tue, 7 Mar 2023 14:24:11 -0800 you wrote:

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

This adds bt_crypto_sirk which attempts to generate a unique SIRK using the following steps:

- Generate a hash (k) using the str as input
- Generate a hash (sirk) using vendor, product, version and source as input
- Encrypt sirk using k as LTK with sef function.

[...]

Here is the summary with links:
- [RFC,v2,01/12] shared/crypto: Add bt_crypto_sirk

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c1dd94cc7f81
  - [RFC,v2,02/12] shared/ad: Add RSI data type
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c2e99aefd337
  - [RFC,v2,03/12] doc: Add set-api
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=6477522e92e3
  - [RFC,v2,04/12] device-api: Add Set property
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5bac4cddb191
  - [RFC,v2,05/12] core: Add initial implementation of DeviceSet interface
    (no matching commit)
  - [RFC,v2,06/12] core: Check if device has RSI
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f95ffcc8b1fe
  - [RFC,v2,07/12] main.conf: Add CSIP profile configurable options
    (no matching commit)
  - [RFC,v2,08/12] shared/csip: Add initial code for handling CSIP
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d297a03b7a61
  - [RFC,v2,09/12] profiles: Add initial code for csip plugin
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9e1eb0a62b3f
  - [RFC,v2,10/12] tools: Add support to generate RSI using SIRK
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c446a64d461b
  - [RFC,v2,11/12] client: Add support for DeviceSet proxy
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=373bafc34ce6
  - [RFC,v2,12/12] client: Use AdvertisingFlags when available
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=815f779aa8e4
Quoted 4 lines

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Quoted 6 lines

Let me know if you guys are happy with this interface to detect Coordinated Sets, it still experimental so we can experiment with it until we think it is stable, regarding the implementation of the transports one major difference here is that we will need to encode left and right separately, not sure how hard it is to do that in pipewire?

As far as the device set DBus interface is concerned, it seems to work fine for me currently (in wip implementation for PW [0]). Don't right now see something that would need to be added/changed in it.

Channel splitting/merging is generally easy in PW. How the playback synchronization is going to work on socket level may determine a bit at what level in PW it is convenient to do though.

---

Laundry list for PW related to this:

Quoted 9 lines

* How to do TX syncronization properly with the ISO sockets needs still some thinking. I have some wip patches [2] that add the timestamps and other socket API that provide timing information to allow synchronization to the Number of Completed packets events. Corresponding Pipewire implementation [3] rate matches to keep the time difference between those events and our audio reference time fixed at e.g. 25ms (2 packets in controller). Not really clear yet if this is a right thing to do to help the controller send packets at the right time.

I have to check with our controller folks, I do recall someone saying that perhaps we should use framed instead of unframed so the controller can better keep up with timings, but it is not yet clear why.

Quoted 3 lines

Here I see LE Read ISO TX Sync with Intel AX210 returning only zero values in Command Complete in btmon for running CIS, so that command doesn't seem to help here.

Yeah, I don't think it is implemented yet.

Quoted 2 lines

* BlueZ doesn't seem to pass on the PAC audio location it reads via read_sink/source_pac_loc, probably very easy to fix.

Will take a look, afaik we fixed something like this not long ago but perhaps you are talking about something different.

Quoted 5 lines

* The CIS in a CIG cannot be started one by one, or connected to same destination. The kernel appears to wait until all CIS sockets in same CIG go to connect state before proceeding to create CIS. The spec does not seem to require this (I have some pre-rfc patches to make it more flexible [1].)

It used to be like that but I actually have to fix it because the controller don't accept multiple CreateCIS in parallel:

https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/tree/net/bluetooth/hci_conn.c#n1907

And it would actually create a relatively big window if we queue and wait for CIS established, because then the controller may set up its scheduling without taking into account the second CIS which will then fail when it comes to its setup, so I think it is better to program them together to avoid having only one side working.

Btw, take a look at how it was done with bluetoothctl> transport.acquire <transport_left> <transport_right>, we have been able to use it to acquire both left/right earbuds and then send pre-encoded files.

Quoted 11 lines

* PW currently does transport acquires synchronously and fails because of that with multiple CIS, but it probably should do them async.

[0] https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1564
[1] https://github.com/pv/linux/commits/iso-fix-multicis
[2] https://github.com/pv/linux/commits/iso-timestamp
[3] https://gitlab.freedesktop.org/pvir/pipewire/-/commits/iso-timestamp-test

--
Pauli Virtanen

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

14. maaliskuuta 2023 2.18.21 GMT+02:00 Luiz Augusto von Dentz <[email protected]> kirjoitti:

Quoted 115 lines

Hi Pauli,

Quoted 76 lines · Pauli Virtanen

Hi,

su, 2023-03-12 kello 22:36 -0700, Luiz Augusto von Dentz kirjoitti:

Quoted 52 lines

Hi Pauli, Frederic,

Quoted 44 lines · On Fri, Mar 10, 2023 at 4:40 PM <[email protected]> wrote:

Hello:

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

Quoted 10 lines · On Tue, 7 Mar 2023 14:24:11 -0800 you wrote:

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

This adds bt_crypto_sirk which attempts to generate a unique SIRK using the following steps:

- Generate a hash (k) using the str as input
- Generate a hash (sirk) using vendor, product, version and source as input
- Encrypt sirk using k as LTK with sef function.

[...]

Here is the summary with links:
- [RFC,v2,01/12] shared/crypto: Add bt_crypto_sirk

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c1dd94cc7f81
  - [RFC,v2,02/12] shared/ad: Add RSI data type
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c2e99aefd337
  - [RFC,v2,03/12] doc: Add set-api
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=6477522e92e3
  - [RFC,v2,04/12] device-api: Add Set property
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5bac4cddb191
  - [RFC,v2,05/12] core: Add initial implementation of DeviceSet interface
    (no matching commit)
  - [RFC,v2,06/12] core: Check if device has RSI
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f95ffcc8b1fe
  - [RFC,v2,07/12] main.conf: Add CSIP profile configurable options
    (no matching commit)
  - [RFC,v2,08/12] shared/csip: Add initial code for handling CSIP
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d297a03b7a61
  - [RFC,v2,09/12] profiles: Add initial code for csip plugin
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9e1eb0a62b3f
  - [RFC,v2,10/12] tools: Add support to generate RSI using SIRK
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c446a64d461b
  - [RFC,v2,11/12] client: Add support for DeviceSet proxy
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=373bafc34ce6
  - [RFC,v2,12/12] client: Use AdvertisingFlags when available
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=815f779aa8e4
Quoted 4 lines

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Quoted 6 lines

Let me know if you guys are happy with this interface to detect Coordinated Sets, it still experimental so we can experiment with it until we think it is stable, regarding the implementation of the transports one major difference here is that we will need to encode left and right separately, not sure how hard it is to do that in pipewire?

As far as the device set DBus interface is concerned, it seems to work fine for me currently (in wip implementation for PW [0]). Don't right now see something that would need to be added/changed in it.

Channel splitting/merging is generally easy in PW. How the playback synchronization is going to work on socket level may determine a bit at what level in PW it is convenient to do though.

---

Laundry list for PW related to this:

Quoted 9 lines

* How to do TX syncronization properly with the ISO sockets needs still some thinking. I have some wip patches [2] that add the timestamps and other socket API that provide timing information to allow synchronization to the Number of Completed packets events. Corresponding Pipewire implementation [3] rate matches to keep the time difference between those events and our audio reference time fixed at e.g. 25ms (2 packets in controller). Not really clear yet if this is a right thing to do to help the controller send packets at the right time.

I have to check with our controller folks, I do recall someone saying that perhaps we should use framed instead of unframed so the controller can better keep up with timings, but it is not yet clear why.

Quoted 3 lines

Here I see LE Read ISO TX Sync with Intel AX210 returning only zero values in Command Complete in btmon for running CIS, so that command doesn't seem to help here.

Yeah, I don't think it is implemented yet.

Quoted 2 lines

* BlueZ doesn't seem to pass on the PAC audio location it reads via read_sink/source_pac_loc, probably very easy to fix.

Will take a look, afaik we fixed something like this not long ago but perhaps you are talking about something different.

Quoted 5 lines

* The CIS in a CIG cannot be started one by one, or connected to same destination. The kernel appears to wait until all CIS sockets in same CIG go to connect state before proceeding to create CIS. The spec does not seem to require this (I have some pre-rfc patches to make it more flexible [1].)

It used to be like that but I actually have to fix it because the controller don't accept multiple CreateCIS in parallel:

Quoted 7 lines

https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/tree/net/bluetooth/hci_conn.c#n1907

And it would actually create a relatively big window if we queue and wait for CIS established, because then the controller may set up its scheduling without taking into account the second CIS which will then fail when it comes to its setup, so I think it is better to program them together to avoid having only one side working.

Hmm, I made it queue and wait for the previous Create CIS to fully complete before emitting the next one, and that did seem to also work (also with TWS playback to the Samsung device). However did not extensively test, so even if allowed by spec risks running to controller issues?

The problem here is that the second CIS is not necessarily going to come, as it may be unrelated device put to same CIG since controller doesn't support multiple CIG.

In principle sound server can acquire always all CIS, but then we should expose also the cig/cis properties on transports so they know which ones are needed.

It could also make sense for BlueZ do it, when any cis in cig is started.

Quoted 19 lines

Btw, take a look at how it was done with bluetoothctl> transport.acquire <transport_left> <transport_right>, we have been able to use it to acquire both left/right earbuds and then send pre-encoded files.

Quoted 11 lines

* PW currently does transport acquires synchronously and fails because of that with multiple CIS, but it probably should do them async.

[0] https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1564
[1] https://github.com/pv/linux/commits/iso-fix-multicis
[2] https://github.com/pv/linux/commits/iso-timestamp
[3] https://gitlab.freedesktop.org/pvir/pipewire/-/commits/iso-timestamp-test

--
Pauli Virtanen

Hi,

author maintainer
#18 lore raw

Hi Pauli,

Quoted 125 lines · Pauli Virtanen

14. maaliskuuta 2023 2.18.21 GMT+02:00 Luiz Augusto von Dentz <[email protected]> kirjoitti:

Quoted 115 lines

Hi Pauli,

Quoted 76 lines · Pauli Virtanen

Hi,

su, 2023-03-12 kello 22:36 -0700, Luiz Augusto von Dentz kirjoitti:

Quoted 52 lines

Hi Pauli, Frederic,

Quoted 44 lines · On Fri, Mar 10, 2023 at 4:40 PM <[email protected]> wrote:

Hello:

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

Quoted 10 lines · On Tue, 7 Mar 2023 14:24:11 -0800 you wrote:

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

This adds bt_crypto_sirk which attempts to generate a unique SIRK using the following steps:

- Generate a hash (k) using the str as input
- Generate a hash (sirk) using vendor, product, version and source as input
- Encrypt sirk using k as LTK with sef function.

[...]

Here is the summary with links:
- [RFC,v2,01/12] shared/crypto: Add bt_crypto_sirk

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c1dd94cc7f81
  - [RFC,v2,02/12] shared/ad: Add RSI data type
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c2e99aefd337
  - [RFC,v2,03/12] doc: Add set-api
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=6477522e92e3
  - [RFC,v2,04/12] device-api: Add Set property
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5bac4cddb191
  - [RFC,v2,05/12] core: Add initial implementation of DeviceSet interface
    (no matching commit)
  - [RFC,v2,06/12] core: Check if device has RSI
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f95ffcc8b1fe
  - [RFC,v2,07/12] main.conf: Add CSIP profile configurable options
    (no matching commit)
  - [RFC,v2,08/12] shared/csip: Add initial code for handling CSIP
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d297a03b7a61
  - [RFC,v2,09/12] profiles: Add initial code for csip plugin
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9e1eb0a62b3f
  - [RFC,v2,10/12] tools: Add support to generate RSI using SIRK
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c446a64d461b
  - [RFC,v2,11/12] client: Add support for DeviceSet proxy
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=373bafc34ce6
  - [RFC,v2,12/12] client: Use AdvertisingFlags when available
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=815f779aa8e4
Quoted 4 lines

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Quoted 6 lines

Let me know if you guys are happy with this interface to detect Coordinated Sets, it still experimental so we can experiment with it until we think it is stable, regarding the implementation of the transports one major difference here is that we will need to encode left and right separately, not sure how hard it is to do that in pipewire?

As far as the device set DBus interface is concerned, it seems to work fine for me currently (in wip implementation for PW [0]). Don't right now see something that would need to be added/changed in it.

Channel splitting/merging is generally easy in PW. How the playback synchronization is going to work on socket level may determine a bit at what level in PW it is convenient to do though.

---

Laundry list for PW related to this:

Quoted 9 lines

* How to do TX syncronization properly with the ISO sockets needs still some thinking. I have some wip patches [2] that add the timestamps and other socket API that provide timing information to allow synchronization to the Number of Completed packets events. Corresponding Pipewire implementation [3] rate matches to keep the time difference between those events and our audio reference time fixed at e.g. 25ms (2 packets in controller). Not really clear yet if this is a right thing to do to help the controller send packets at the right time.

I have to check with our controller folks, I do recall someone saying that perhaps we should use framed instead of unframed so the controller can better keep up with timings, but it is not yet clear why.

Quoted 3 lines

Here I see LE Read ISO TX Sync with Intel AX210 returning only zero values in Command Complete in btmon for running CIS, so that command doesn't seem to help here.

Yeah, I don't think it is implemented yet.

Quoted 2 lines

* BlueZ doesn't seem to pass on the PAC audio location it reads via read_sink/source_pac_loc, probably very easy to fix.

Will take a look, afaik we fixed something like this not long ago but perhaps you are talking about something different.

Quoted 5 lines

* The CIS in a CIG cannot be started one by one, or connected to same destination. The kernel appears to wait until all CIS sockets in same CIG go to connect state before proceeding to create CIS. The spec does not seem to require this (I have some pre-rfc patches to make it more flexible [1].)

It used to be like that but I actually have to fix it because the controller don't accept multiple CreateCIS in parallel:

Quoted 7 lines

https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/tree/net/bluetooth/hci_conn.c#n1907

And it would actually create a relatively big window if we queue and wait for CIS established, because then the controller may set up its scheduling without taking into account the second CIS which will then fail when it comes to its setup, so I think it is better to program them together to avoid having only one side working.

Quoted 19 lines

Hmm, I made it queue and wait for the previous Create CIS to fully complete before emitting the next one, and that did seem to also work (also with TWS playback to the Samsung device). However did not extensively test, so even if allowed by spec risks running to controller issues?

The problem here is that the second CIS is not necessarily going to come, as it may be unrelated device put to same CIG since controller doesn't support multiple CIG.

In principle sound server can acquire always all CIS, but then we should expose also the cig/cis properties on transports so they know which ones are needed.

It could also make sense for BlueZ do it, when any cis in cig is started.

Quoted 10 lines

Btw, take a look at how it was done with bluetoothctl> transport.acquire <transport_left> <transport_right>, we have been able to use it to acquire both left/right earbuds and then send pre-encoded files.

Quoted 5 lines

* PW currently does transport acquires synchronously and fails because of that with multiple CIS, but it probably should do them async.

[0] https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1564

Did you make any progress on these changes above? Looks like the pull request is still open, I wonder if you hit some blocker?

Quoted 11 lines
Quoted 9 lines
Quoted 6 lines

[1] https://github.com/pv/linux/commits/iso-fix-multicis
[2] https://github.com/pv/linux/commits/iso-timestamp
[3] https://gitlab.freedesktop.org/pvir/pipewire/-/commits/iso-timestamp-test

--
Pauli Virtanen

Hi,

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

Hi Luiz,

ke, 2023-04-05 kello 17:16 -0700, Luiz Augusto von Dentz kirjoitti:

Quoted 142 lines

Hi Pauli,

Quoted 139 lines · Pauli Virtanen

14. maaliskuuta 2023 2.18.21 GMT+02:00 Luiz Augusto von Dentz <[email protected]> kirjoitti:

Quoted 115 lines

Hi Pauli,

Quoted 76 lines · Pauli Virtanen

Hi,

su, 2023-03-12 kello 22:36 -0700, Luiz Augusto von Dentz kirjoitti:

Quoted 52 lines

Hi Pauli, Frederic,

Quoted 44 lines · On Fri, Mar 10, 2023 at 4:40 PM <[email protected]> wrote:

Hello:

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

Quoted 10 lines · On Tue, 7 Mar 2023 14:24:11 -0800 you wrote:

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

This adds bt_crypto_sirk which attempts to generate a unique SIRK using the following steps:

- Generate a hash (k) using the str as input
- Generate a hash (sirk) using vendor, product, version and source as input
- Encrypt sirk using k as LTK with sef function.

[...]

Here is the summary with links:
- [RFC,v2,01/12] shared/crypto: Add bt_crypto_sirk

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c1dd94cc7f81
  - [RFC,v2,02/12] shared/ad: Add RSI data type
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c2e99aefd337
  - [RFC,v2,03/12] doc: Add set-api
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=6477522e92e3
  - [RFC,v2,04/12] device-api: Add Set property
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5bac4cddb191
  - [RFC,v2,05/12] core: Add initial implementation of DeviceSet interface
    (no matching commit)
  - [RFC,v2,06/12] core: Check if device has RSI
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f95ffcc8b1fe
  - [RFC,v2,07/12] main.conf: Add CSIP profile configurable options
    (no matching commit)
  - [RFC,v2,08/12] shared/csip: Add initial code for handling CSIP
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d297a03b7a61
  - [RFC,v2,09/12] profiles: Add initial code for csip plugin
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9e1eb0a62b3f
  - [RFC,v2,10/12] tools: Add support to generate RSI using SIRK
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c446a64d461b
  - [RFC,v2,11/12] client: Add support for DeviceSet proxy
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=373bafc34ce6
  - [RFC,v2,12/12] client: Use AdvertisingFlags when available
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=815f779aa8e4
Quoted 4 lines

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Quoted 6 lines

Let me know if you guys are happy with this interface to detect Coordinated Sets, it still experimental so we can experiment with it until we think it is stable, regarding the implementation of the transports one major difference here is that we will need to encode left and right separately, not sure how hard it is to do that in pipewire?

As far as the device set DBus interface is concerned, it seems to work fine for me currently (in wip implementation for PW [0]). Don't right now see something that would need to be added/changed in it.

Channel splitting/merging is generally easy in PW. How the playback synchronization is going to work on socket level may determine a bit at what level in PW it is convenient to do though.

---

Laundry list for PW related to this:

Quoted 9 lines

* How to do TX syncronization properly with the ISO sockets needs still some thinking. I have some wip patches [2] that add the timestamps and other socket API that provide timing information to allow synchronization to the Number of Completed packets events. Corresponding Pipewire implementation [3] rate matches to keep the time difference between those events and our audio reference time fixed at e.g. 25ms (2 packets in controller). Not really clear yet if this is a right thing to do to help the controller send packets at the right time.

I have to check with our controller folks, I do recall someone saying that perhaps we should use framed instead of unframed so the controller can better keep up with timings, but it is not yet clear why.

Quoted 3 lines

Here I see LE Read ISO TX Sync with Intel AX210 returning only zero values in Command Complete in btmon for running CIS, so that command doesn't seem to help here.

Yeah, I don't think it is implemented yet.

Quoted 2 lines

* BlueZ doesn't seem to pass on the PAC audio location it reads via read_sink/source_pac_loc, probably very easy to fix.

Will take a look, afaik we fixed something like this not long ago but perhaps you are talking about something different.

Quoted 5 lines

* The CIS in a CIG cannot be started one by one, or connected to same destination. The kernel appears to wait until all CIS sockets in same CIG go to connect state before proceeding to create CIS. The spec does not seem to require this (I have some pre-rfc patches to make it more flexible [1].)

It used to be like that but I actually have to fix it because the controller don't accept multiple CreateCIS in parallel:

Quoted 7 lines

https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/tree/net/bluetooth/hci_conn.c#n1907

And it would actually create a relatively big window if we queue and wait for CIS established, because then the controller may set up its scheduling without taking into account the second CIS which will then fail when it comes to its setup, so I think it is better to program them together to avoid having only one side working.

Hmm, I made it queue and wait for the previous Create CIS to fully complete before emitting the next one, and that did seem to also work (also with TWS playback to the Samsung device). However did not extensively test, so even if allowed by spec risks running to controller issues?

The problem here is that the second CIS is not necessarily going to come, as it may be unrelated device put to same CIG since controller doesn't support multiple CIG.

In principle sound server can acquire always all CIS, but then we should expose also the cig/cis properties on transports so they know which ones are needed.

It could also make sense for BlueZ do it, when any cis in cig is started.

Quoted 5 lines

Btw, take a look at how it was done with bluetoothctl> transport.acquire <transport_left> <transport_right>, we have been able to use it to acquire both left/right earbuds and then send pre-encoded files.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

* PW currently does transport acquires synchronously and fails because of that with multiple CIS, but it probably should do them async.

[0] https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1564

Did you make any progress on these changes above? Looks like the pull request is still open, I wonder if you hit some blocker?

The device set part is fine now.

However, I've been first looking at sorting out TWS playback synchronization, and ran to some issues there.

Current laundry list:

(1) The playback to the left/right earbuds can rarely desynchronize spontaneously during playback, even though we send packets to both ISO socket fds at the same time on ISO interval schedule.

Possibly, it goes to a state where the two CIS are off by one packet due to some queue on controller side. Desynchronization by 10ms can be heard easily in TWS earbuds as it transforms click at stereo center to separate clicks on left and right as brain interprets it.

It usually resynchronizes if we halt sending packets to both CIS for ~ 50+ ms and then continue, and sometimes it resynchronizes spontaneously.

I've been looking at the conn->sent values at packet completion event time, but it is not clear it's possible to distinguish the desynchronized state from synchronized one, as it appears in both you can have either 0 or 1 and occasionally 2 packets not yet acked by the controller.

(2) With the Samsung device, Intel AX210 fails LE Create CIS for the CIG with both earbuds with current kernel (btmon logs below).  It works if only one device is connected. As a workaround, I'm currently using a patch [1] that changes it to do LE Create CIS for the CIG one by one. Since that works, could be some controller issue.

(3) The playback from Intel AX210 -> Samsung device apparently has some issue with the radio link/etc, as playback sometimes has crackling and distortion. I thought earlier this was some TX sync issue on sender side, but keeping 1+ packets queued in controller all the time did not solve it. Since also RX appears to miss packets, it's maybe not related to that after all.

(4) The Samsung device has some issue in that disabling source ASEs does not complete. Workaround is to never release transports, but would need to take a look again at this to be sure if it's only device issue.

(5) Sometimes when connecting one earbud, the other earbud fails to connect. Haven't yet looked into this.

Because of (2) and (3), I'm not sure now if (1) is general issue or only for this device combination. However, how things are done right now, there doesn't seem to be a way for the user to detect CIS desynchronization or recover from it.

Some things I tried: setting matching sequence numbers to the HCI ISO packets for the two CIS, but doesn't seem to do anything (maybe controller ignores them?). Setting packet timestamps does something, but appears to require synchronizing to the controller clock to produce any audio, which cannot be done since the controller does not have working LE Read ISO TX Sync.

I also thought that maybe kernel hci_sched_iso could cause it, but at least changing it to send packets to controller in sequence number (provided by PW) order didn't seem to change anything.

So right now at least this TWS device usually works OK, but not yet robustly enough to be non-experimental feature.

The Intel AX210 problem:

[ 1627.217064] usb 1-5: new full-speed USB device number 16 using xhci_hcd
[ 1627.370401] usb 1-5: New USB device found, idVendor=8087, idProduct=0032, bcdDevice= 0.00
[ 1627.370408] usb 1-5: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 1627.374671] Bluetooth: hci0: Device revision is 0
[ 1627.374676] Bluetooth: hci0: Secure boot is enabled
[ 1627.374678] Bluetooth: hci0: OTP lock is enabled
[ 1627.374680] Bluetooth: hci0: API lock is enabled
[ 1627.374681] Bluetooth: hci0: Debug lock is disabled
[ 1627.374683] Bluetooth: hci0: Minimum firmware build 1 week 10 2014
[ 1627.374685] Bluetooth: hci0: Bootloader timestamp 2019.40 buildtype 1 build 38
[ 1627.410381] Bluetooth: hci0: Found device firmware: intel/ibt-0041-0041.sfi
[ 1627.410446] Bluetooth: hci0: Boot Address: 0x100800
[ 1627.410447] Bluetooth: hci0: Firmware Version: 107-51.22
[ 1629.568723] Bluetooth: hci0: Waiting for firmware download to complete
[ 1629.569770] Bluetooth: hci0: Firmware loaded in 2108786 usecs
[ 1629.570011] Bluetooth: hci0: Waiting for device to boot
[ 1629.595622] Bluetooth: hci0: Device booted in 25187 usecs
[ 1629.595647] Bluetooth: hci0: Malformed MSFT vendor event: 0x02
[ 1629.595923] Bluetooth: hci0: Found Intel DDC parameters: intel/ibt-0041-0041.ddc
[ 1629.597711] Bluetooth: hci0: Applying Intel DDC parameters completed
[ 1629.600707] Bluetooth: hci0: Firmware timestamp 2022.51 buildtype 1 build 56683
[ 1629.677307] Bluetooth: MGMT ver 1.22

< HCI Command: LE Set Connect.. (0x08|0x0062) plen 33 #16903 [hci0] 802.544515

        CIG ID: 0x00
        Central to Peripheral SDU Interval: 10000 us (0x002710)
        Peripheral to Central SDU Interval: 10000 us (0x002710)
        SCA: 201 - 500 ppm (0x00)
        Packing: Sequential (0x00)
        Framing: Unframed (0x00)
        Central to Peripheral Maximum Latency: 20 ms (0x0014)
        Peripheral to Central Maximum Latency: 20 ms (0x0014)
        Number of CIS: 2
        CIS ID: 0x00
        Central to Peripheral Maximum SDU Size: 120
        Peripheral to Central Maximum SDU Size: 120
        Central to Peripheral PHY: LE 2M (0x02)
        Peripheral to Central PHY: LE 2M (0x02)
        Central to Peripheral Retransmission attempts: 0x05
        Peripheral to Central Retransmission attempts: 0x05
        CIS ID: 0x01
        Central to Peripheral Maximum SDU Size: 120
        Peripheral to Central Maximum SDU Size: 120
        Central to Peripheral PHY: LE 2M (0x02)
        Peripheral to Central PHY: LE 2M (0x02)
        Central to Peripheral Retransmission attempts: 0x05
        Peripheral to Central Retransmission attempts: 0x05
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 10 #16904 [hci0] 802.547134

      LE Set Connected Isochronous Group Parameters (0x08|0x0062) ncmd 1
        Status: Success (0x00)
        CIG ID: 0x00
        Number of Handles: 2
        Connection Handle #0: 2560
        Connection Handle #1: 2561
...
< HCI Command: LE Create Conne.. (0x08|0x0064) plen 9  #16928 [hci0] 833.626566
        Number of CIS: 2
        CIS Handle: 2560
        ACL Handle: 3585
        CIS Handle: 2561
        ACL Handle: 3586
Quoted 1 line

HCI Event: Command Status (0x0f) plen 4 #16929 [hci0] 833.628188

      LE Create Connected Isochronous Stream (0x08|0x0064) ncmd 1
        Status: Success (0x00)
Quoted 1 line

HCI Event: LE Meta Event (0x3e) plen 29 #16930 [hci0] 833.670453

      LE Connected Isochronous Stream Established (0x19)
        Status: Unspecified Error (0x1f)
        Connection Handle: 2561
        CIG Synchronization Delay: 89856 us (0x015f00)
        CIS Synchronization Delay: 4718843 us (0x4800fb)
        Central to Peripheral Latency: 1 us (0x000001)
        Peripheral to Central Latency: 0 us (0x000000)
        Central to Peripheral PHY: Reserved (0x00)
        Peripheral to Central PHY: Reserved (0x00)
        Number of Subevents: 0
        Central to Peripheral Burst Number: 0
        Peripheral to Central Burst Number: 0
        Central to Peripheral Flush Timeout: 0
        Peripheral to Central Flush Timeout: 0
        Central to Peripheral MTU: 1536
        Peripheral to Central MTU: 0
        ISO Interval: 10752

= bluetoothd: profiles/audio/bap.c:iso_connect_cb() connect to 2.. 833.670831

Signature · 1 line
Pauli Virtanen
Quoted 3 lines
Quoted 3 lines

[1] https://github.com/pv/linux/commits/iso-fix-multicis
[2] https://github.com/pv/linux/commits/iso-timestamp
[3] https://gitlab.freedesktop.org/pvir/pipewire/-/commits/iso-timestamp-test

author maintainer
#20 lore raw

Hi Pauli,

Quoted 176 lines · Pauli Virtanen

Hi Luiz,

ke, 2023-04-05 kello 17:16 -0700, Luiz Augusto von Dentz kirjoitti:

Quoted 142 lines

Hi Pauli,

Quoted 139 lines · Pauli Virtanen

14. maaliskuuta 2023 2.18.21 GMT+02:00 Luiz Augusto von Dentz <[email protected]> kirjoitti:

Quoted 115 lines

Hi Pauli,

Quoted 76 lines · Pauli Virtanen

Hi,

su, 2023-03-12 kello 22:36 -0700, Luiz Augusto von Dentz kirjoitti:

Quoted 52 lines

Hi Pauli, Frederic,

Quoted 44 lines · On Fri, Mar 10, 2023 at 4:40 PM <[email protected]> wrote:

Hello:

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

Quoted 10 lines · On Tue, 7 Mar 2023 14:24:11 -0800 you wrote:

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

This adds bt_crypto_sirk which attempts to generate a unique SIRK using the following steps:

- Generate a hash (k) using the str as input
- Generate a hash (sirk) using vendor, product, version and source as input
- Encrypt sirk using k as LTK with sef function.

[...]

Here is the summary with links:
- [RFC,v2,01/12] shared/crypto: Add bt_crypto_sirk

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c1dd94cc7f81
  - [RFC,v2,02/12] shared/ad: Add RSI data type
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c2e99aefd337
  - [RFC,v2,03/12] doc: Add set-api
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=6477522e92e3
  - [RFC,v2,04/12] device-api: Add Set property
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5bac4cddb191
  - [RFC,v2,05/12] core: Add initial implementation of DeviceSet interface
    (no matching commit)
  - [RFC,v2,06/12] core: Check if device has RSI
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f95ffcc8b1fe
  - [RFC,v2,07/12] main.conf: Add CSIP profile configurable options
    (no matching commit)
  - [RFC,v2,08/12] shared/csip: Add initial code for handling CSIP
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d297a03b7a61
  - [RFC,v2,09/12] profiles: Add initial code for csip plugin
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9e1eb0a62b3f
  - [RFC,v2,10/12] tools: Add support to generate RSI using SIRK
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c446a64d461b
  - [RFC,v2,11/12] client: Add support for DeviceSet proxy
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=373bafc34ce6
  - [RFC,v2,12/12] client: Use AdvertisingFlags when available
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=815f779aa8e4
Quoted 4 lines

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Quoted 6 lines

Let me know if you guys are happy with this interface to detect Coordinated Sets, it still experimental so we can experiment with it until we think it is stable, regarding the implementation of the transports one major difference here is that we will need to encode left and right separately, not sure how hard it is to do that in pipewire?

As far as the device set DBus interface is concerned, it seems to work fine for me currently (in wip implementation for PW [0]). Don't right now see something that would need to be added/changed in it.

Channel splitting/merging is generally easy in PW. How the playback synchronization is going to work on socket level may determine a bit at what level in PW it is convenient to do though.

---

Laundry list for PW related to this:

Quoted 9 lines

* How to do TX syncronization properly with the ISO sockets needs still some thinking. I have some wip patches [2] that add the timestamps and other socket API that provide timing information to allow synchronization to the Number of Completed packets events. Corresponding Pipewire implementation [3] rate matches to keep the time difference between those events and our audio reference time fixed at e.g. 25ms (2 packets in controller). Not really clear yet if this is a right thing to do to help the controller send packets at the right time.

I have to check with our controller folks, I do recall someone saying that perhaps we should use framed instead of unframed so the controller can better keep up with timings, but it is not yet clear why.

Quoted 3 lines

Here I see LE Read ISO TX Sync with Intel AX210 returning only zero values in Command Complete in btmon for running CIS, so that command doesn't seem to help here.

Yeah, I don't think it is implemented yet.

Quoted 2 lines

* BlueZ doesn't seem to pass on the PAC audio location it reads via read_sink/source_pac_loc, probably very easy to fix.

Will take a look, afaik we fixed something like this not long ago but perhaps you are talking about something different.

Quoted 5 lines

* The CIS in a CIG cannot be started one by one, or connected to same destination. The kernel appears to wait until all CIS sockets in same CIG go to connect state before proceeding to create CIS. The spec does not seem to require this (I have some pre-rfc patches to make it more flexible [1].)

It used to be like that but I actually have to fix it because the controller don't accept multiple CreateCIS in parallel:

Quoted 7 lines

https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/tree/net/bluetooth/hci_conn.c#n1907

And it would actually create a relatively big window if we queue and wait for CIS established, because then the controller may set up its scheduling without taking into account the second CIS which will then fail when it comes to its setup, so I think it is better to program them together to avoid having only one side working.

Hmm, I made it queue and wait for the previous Create CIS to fully complete before emitting the next one, and that did seem to also work (also with TWS playback to the Samsung device). However did not extensively test, so even if allowed by spec risks running to controller issues?

The problem here is that the second CIS is not necessarily going to come, as it may be unrelated device put to same CIG since controller doesn't support multiple CIG.

In principle sound server can acquire always all CIS, but then we should expose also the cig/cis properties on transports so they know which ones are needed.

It could also make sense for BlueZ do it, when any cis in cig is started.

Quoted 5 lines

Btw, take a look at how it was done with bluetoothctl> transport.acquire <transport_left> <transport_right>, we have been able to use it to acquire both left/right earbuds and then send pre-encoded files.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

* PW currently does transport acquires synchronously and fails because of that with multiple CIS, but it probably should do them async.

[0] https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1564

Did you make any progress on these changes above? Looks like the pull request is still open, I wonder if you hit some blocker?

The device set part is fine now.

However, I've been first looking at sorting out TWS playback synchronization, and ran to some issues there.

Current laundry list:

(1) The playback to the left/right earbuds can rarely desynchronize spontaneously during playback, even though we send packets to both ISO socket fds at the same time on ISO interval schedule.

Possibly, it goes to a state where the two CIS are off by one packet due to some queue on controller side. Desynchronization by 10ms can be heard easily in TWS earbuds as it transforms click at stereo center to separate clicks on left and right as brain interprets it.

It usually resynchronizes if we halt sending packets to both CIS for ~ 50+ ms and then continue, and sometimes it resynchronizes spontaneously.

Quoted 5 lines

I've been looking at the conn->sent values at packet completion event time, but it is not clear it's possible to distinguish the desynchronized state from synchronized one, as it appears in both you can have either 0 or 1 and occasionally 2 packets not yet acked by the controller.

Interesting, what is the presentation delay configured, in theory that should be used to synchronize the streams, we may need a way to measure this latency and attempt to compensate for it somehow if transfer speed variates.

Quoted 6 lines

(2) With the Samsung device, Intel AX210 fails LE Create CIS for the CIG with both earbuds with current kernel (btmon logs below). It works if only one device is connected. As a workaround, I'm currently using a patch [1] that changes it to do LE Create CIS for the CIG one by one. Since that works, could be some controller issue.

I believe we fixed that, are you running with the latest firmware and bluetooth-next? On the kernel side you may need the following:

https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/commit/?id=70eff70d453bdb529d8233f59e32c1ffedac7685

Quoted 7 lines

(3) The playback from Intel AX210 -> Samsung device apparently has some issue with the radio link/etc, as playback sometimes has crackling and distortion. I thought earlier this was some TX sync issue on sender side, but keeping 1+ packets queued in controller all the time did not solve it. Since also RX appears to miss packets, it's maybe not related to that after all.

This might be hard to figure out without air traces, will need to reproduce it internally.

Quoted 4 lines

(4) The Samsung device has some issue in that disabling source ASEs does not complete. Workaround is to never release transports, but would need to take a look again at this to be sure if it's only device issue.

Make sure you have btmon to collect the traces when this happens.

Quoted 3 lines

(5) Sometimes when connecting one earbud, the other earbud fails to connect. Haven't yet looked into this.

Ive seen that, this may actually be something like:

https://github.com/bluez/bluez/issues/340#issuecomment-1494877679

This is less pronounced when we use the auto-connect list, since that attempts to connect whenever it sees the device advertising so it will continue to attempt multiple times, with the latest bluez tree this is now the default behavior:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/commit/?id=ca07d198f9c7d289e95091c30ed15bff2106a7db

Quoted 13 lines

Because of (2) and (3), I'm not sure now if (1) is general issue or only for this device combination. However, how things are done right now, there doesn't seem to be a way for the user to detect CIS desynchronization or recover from it.

Some things I tried: setting matching sequence numbers to the HCI ISO packets for the two CIS, but doesn't seem to do anything (maybe controller ignores them?). Setting packet timestamps does something, but appears to require synchronizing to the controller clock to produce any audio, which cannot be done since the controller does not have working LE Read ISO TX Sync.

Quoted 6 lines

I also thought that maybe kernel hci_sched_iso could cause it, but at least changing it to send packets to controller in sequence number (provided by PW) order didn't seem to change anything.

So right now at least this TWS device usually works OK, but not yet robustly enough to be non-experimental feature.

Yeah, I think there will be some time needed to mature the stacks and firmware to match what we currently have in Classic, but it is great to have this sort of feedback from the audio subsystem.

Quoted 85 lines

The Intel AX210 problem:

[ 1627.217064] usb 1-5: new full-speed USB device number 16 using xhci_hcd
[ 1627.370401] usb 1-5: New USB device found, idVendor=8087, idProduct=0032, bcdDevice= 0.00
[ 1627.370408] usb 1-5: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 1627.374671] Bluetooth: hci0: Device revision is 0
[ 1627.374676] Bluetooth: hci0: Secure boot is enabled
[ 1627.374678] Bluetooth: hci0: OTP lock is enabled
[ 1627.374680] Bluetooth: hci0: API lock is enabled
[ 1627.374681] Bluetooth: hci0: Debug lock is disabled
[ 1627.374683] Bluetooth: hci0: Minimum firmware build 1 week 10 2014
[ 1627.374685] Bluetooth: hci0: Bootloader timestamp 2019.40 buildtype 1 build 38
[ 1627.410381] Bluetooth: hci0: Found device firmware: intel/ibt-0041-0041.sfi
[ 1627.410446] Bluetooth: hci0: Boot Address: 0x100800
[ 1627.410447] Bluetooth: hci0: Firmware Version: 107-51.22
[ 1629.568723] Bluetooth: hci0: Waiting for firmware download to complete
[ 1629.569770] Bluetooth: hci0: Firmware loaded in 2108786 usecs
[ 1629.570011] Bluetooth: hci0: Waiting for device to boot
[ 1629.595622] Bluetooth: hci0: Device booted in 25187 usecs
[ 1629.595647] Bluetooth: hci0: Malformed MSFT vendor event: 0x02
[ 1629.595923] Bluetooth: hci0: Found Intel DDC parameters: intel/ibt-0041-0041.ddc
[ 1629.597711] Bluetooth: hci0: Applying Intel DDC parameters completed
[ 1629.600707] Bluetooth: hci0: Firmware timestamp 2022.51 buildtype 1 build 56683
[ 1629.677307] Bluetooth: MGMT ver 1.22

< HCI Command: LE Set Connect.. (0x08|0x0062) plen 33 #16903 [hci0] 802.544515

        CIG ID: 0x00
        Central to Peripheral SDU Interval: 10000 us (0x002710)
        Peripheral to Central SDU Interval: 10000 us (0x002710)
        SCA: 201 - 500 ppm (0x00)
        Packing: Sequential (0x00)
        Framing: Unframed (0x00)
        Central to Peripheral Maximum Latency: 20 ms (0x0014)
        Peripheral to Central Maximum Latency: 20 ms (0x0014)
        Number of CIS: 2
        CIS ID: 0x00
        Central to Peripheral Maximum SDU Size: 120
        Peripheral to Central Maximum SDU Size: 120
        Central to Peripheral PHY: LE 2M (0x02)
        Peripheral to Central PHY: LE 2M (0x02)
        Central to Peripheral Retransmission attempts: 0x05
        Peripheral to Central Retransmission attempts: 0x05
        CIS ID: 0x01
        Central to Peripheral Maximum SDU Size: 120
        Peripheral to Central Maximum SDU Size: 120
        Central to Peripheral PHY: LE 2M (0x02)
        Peripheral to Central PHY: LE 2M (0x02)
        Central to Peripheral Retransmission attempts: 0x05
        Peripheral to Central Retransmission attempts: 0x05
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 10 #16904 [hci0] 802.547134

      LE Set Connected Isochronous Group Parameters (0x08|0x0062) ncmd 1
        Status: Success (0x00)
        CIG ID: 0x00
        Number of Handles: 2
        Connection Handle #0: 2560
        Connection Handle #1: 2561
...
< HCI Command: LE Create Conne.. (0x08|0x0064) plen 9  #16928 [hci0] 833.626566
        Number of CIS: 2
        CIS Handle: 2560
        ACL Handle: 3585
        CIS Handle: 2561
        ACL Handle: 3586
Quoted 1 line

HCI Event: Command Status (0x0f) plen 4 #16929 [hci0] 833.628188

      LE Create Connected Isochronous Stream (0x08|0x0064) ncmd 1
        Status: Success (0x00)
Quoted 1 line

HCI Event: LE Meta Event (0x3e) plen 29 #16930 [hci0] 833.670453

      LE Connected Isochronous Stream Established (0x19)
        Status: Unspecified Error (0x1f)
        Connection Handle: 2561
        CIG Synchronization Delay: 89856 us (0x015f00)
        CIS Synchronization Delay: 4718843 us (0x4800fb)
        Central to Peripheral Latency: 1 us (0x000001)
        Peripheral to Central Latency: 0 us (0x000000)
        Central to Peripheral PHY: Reserved (0x00)
        Peripheral to Central PHY: Reserved (0x00)
        Number of Subevents: 0
        Central to Peripheral Burst Number: 0
        Peripheral to Central Burst Number: 0
        Central to Peripheral Flush Timeout: 0
        Peripheral to Central Flush Timeout: 0
        Central to Peripheral MTU: 1536
        Peripheral to Central MTU: 0
        ISO Interval: 10752
Quoted 11 lines

= bluetoothd: profiles/audio/bap.c:iso_connect_cb() connect to 2.. 833.670831

--
Pauli Virtanen

Quoted 3 lines
Quoted 3 lines

[1] https://github.com/pv/linux/commits/iso-fix-multicis
[2] https://github.com/pv/linux/commits/iso-timestamp
[3] https://gitlab.freedesktop.org/pvir/pipewire/-/commits/iso-timestamp-test

https://gitlab.freedesktop.org/pvir/pipewire/-/commit/667ab3c693e0425568ac405a6a311754ed798653

In the isotest/bluetoothctl we actually use the latency/interval to determine how many packets we have to send at each ISO interval:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/tools/isotest.c#n704

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

Hi Pauli,

Quoted 357 lines · Luiz Augusto von Dentz

Hi Pauli,

Quoted 176 lines · Pauli Virtanen

Hi Luiz,

ke, 2023-04-05 kello 17:16 -0700, Luiz Augusto von Dentz kirjoitti:

Quoted 142 lines

Hi Pauli,

Quoted 139 lines · Pauli Virtanen

14. maaliskuuta 2023 2.18.21 GMT+02:00 Luiz Augusto von Dentz <[email protected]> kirjoitti:

Quoted 115 lines

Hi Pauli,

Quoted 76 lines · Pauli Virtanen

Hi,

su, 2023-03-12 kello 22:36 -0700, Luiz Augusto von Dentz kirjoitti:

Quoted 52 lines

Hi Pauli, Frederic,

Quoted 44 lines · On Fri, Mar 10, 2023 at 4:40 PM <[email protected]> wrote:

Hello:

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

Quoted 10 lines · On Tue, 7 Mar 2023 14:24:11 -0800 you wrote:

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

This adds bt_crypto_sirk which attempts to generate a unique SIRK using the following steps:

- Generate a hash (k) using the str as input
- Generate a hash (sirk) using vendor, product, version and source as input
- Encrypt sirk using k as LTK with sef function.

[...]

Here is the summary with links:
- [RFC,v2,01/12] shared/crypto: Add bt_crypto_sirk

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c1dd94cc7f81
  - [RFC,v2,02/12] shared/ad: Add RSI data type
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c2e99aefd337
  - [RFC,v2,03/12] doc: Add set-api
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=6477522e92e3
  - [RFC,v2,04/12] device-api: Add Set property
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5bac4cddb191
  - [RFC,v2,05/12] core: Add initial implementation of DeviceSet interface
    (no matching commit)
  - [RFC,v2,06/12] core: Check if device has RSI
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f95ffcc8b1fe
  - [RFC,v2,07/12] main.conf: Add CSIP profile configurable options
    (no matching commit)
  - [RFC,v2,08/12] shared/csip: Add initial code for handling CSIP
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d297a03b7a61
  - [RFC,v2,09/12] profiles: Add initial code for csip plugin
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9e1eb0a62b3f
  - [RFC,v2,10/12] tools: Add support to generate RSI using SIRK
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c446a64d461b
  - [RFC,v2,11/12] client: Add support for DeviceSet proxy
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=373bafc34ce6
  - [RFC,v2,12/12] client: Use AdvertisingFlags when available
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=815f779aa8e4
Quoted 4 lines

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Quoted 6 lines

Let me know if you guys are happy with this interface to detect Coordinated Sets, it still experimental so we can experiment with it until we think it is stable, regarding the implementation of the transports one major difference here is that we will need to encode left and right separately, not sure how hard it is to do that in pipewire?

As far as the device set DBus interface is concerned, it seems to work fine for me currently (in wip implementation for PW [0]). Don't right now see something that would need to be added/changed in it.

Channel splitting/merging is generally easy in PW. How the playback synchronization is going to work on socket level may determine a bit at what level in PW it is convenient to do though.

---

Laundry list for PW related to this:

Quoted 9 lines

* How to do TX syncronization properly with the ISO sockets needs still some thinking. I have some wip patches [2] that add the timestamps and other socket API that provide timing information to allow synchronization to the Number of Completed packets events. Corresponding Pipewire implementation [3] rate matches to keep the time difference between those events and our audio reference time fixed at e.g. 25ms (2 packets in controller). Not really clear yet if this is a right thing to do to help the controller send packets at the right time.

I have to check with our controller folks, I do recall someone saying that perhaps we should use framed instead of unframed so the controller can better keep up with timings, but it is not yet clear why.

Quoted 3 lines

Here I see LE Read ISO TX Sync with Intel AX210 returning only zero values in Command Complete in btmon for running CIS, so that command doesn't seem to help here.

Yeah, I don't think it is implemented yet.

Quoted 2 lines

* BlueZ doesn't seem to pass on the PAC audio location it reads via read_sink/source_pac_loc, probably very easy to fix.

Will take a look, afaik we fixed something like this not long ago but perhaps you are talking about something different.

Quoted 5 lines

* The CIS in a CIG cannot be started one by one, or connected to same destination. The kernel appears to wait until all CIS sockets in same CIG go to connect state before proceeding to create CIS. The spec does not seem to require this (I have some pre-rfc patches to make it more flexible [1].)

It used to be like that but I actually have to fix it because the controller don't accept multiple CreateCIS in parallel:

Quoted 7 lines

https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/tree/net/bluetooth/hci_conn.c#n1907

And it would actually create a relatively big window if we queue and wait for CIS established, because then the controller may set up its scheduling without taking into account the second CIS which will then fail when it comes to its setup, so I think it is better to program them together to avoid having only one side working.

Hmm, I made it queue and wait for the previous Create CIS to fully complete before emitting the next one, and that did seem to also work (also with TWS playback to the Samsung device). However did not extensively test, so even if allowed by spec risks running to controller issues?

The problem here is that the second CIS is not necessarily going to come, as it may be unrelated device put to same CIG since controller doesn't support multiple CIG.

In principle sound server can acquire always all CIS, but then we should expose also the cig/cis properties on transports so they know which ones are needed.

It could also make sense for BlueZ do it, when any cis in cig is started.

Quoted 5 lines

Btw, take a look at how it was done with bluetoothctl> transport.acquire <transport_left> <transport_right>, we have been able to use it to acquire both left/right earbuds and then send pre-encoded files.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

* PW currently does transport acquires synchronously and fails because of that with multiple CIS, but it probably should do them async.

[0] https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1564

Did you make any progress on these changes above? Looks like the pull request is still open, I wonder if you hit some blocker?

The device set part is fine now.

However, I've been first looking at sorting out TWS playback synchronization, and ran to some issues there.

Current laundry list:

(1) The playback to the left/right earbuds can rarely desynchronize spontaneously during playback, even though we send packets to both ISO socket fds at the same time on ISO interval schedule.

Possibly, it goes to a state where the two CIS are off by one packet due to some queue on controller side. Desynchronization by 10ms can be heard easily in TWS earbuds as it transforms click at stereo center to separate clicks on left and right as brain interprets it.

It usually resynchronizes if we halt sending packets to both CIS for ~ 50+ ms and then continue, and sometimes it resynchronizes spontaneously.

Quoted 5 lines

I've been looking at the conn->sent values at packet completion event time, but it is not clear it's possible to distinguish the desynchronized state from synchronized one, as it appears in both you can have either 0 or 1 and occasionally 2 packets not yet acked by the controller.

Interesting, what is the presentation delay configured, in theory that should be used to synchronize the streams, we may need a way to measure this latency and attempt to compensate for it somehow if transfer speed variates.

Quoted 6 lines

(2) With the Samsung device, Intel AX210 fails LE Create CIS for the CIG with both earbuds with current kernel (btmon logs below). It works if only one device is connected. As a workaround, I'm currently using a patch [1] that changes it to do LE Create CIS for the CIG one by one. Since that works, could be some controller issue.

I believe we fixed that, are you running with the latest firmware and bluetooth-next? On the kernel side you may need the following:

https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/commit/?id=70eff70d453bdb529d8233f59e32c1ffedac7685

Quoted 7 lines

(3) The playback from Intel AX210 -> Samsung device apparently has some issue with the radio link/etc, as playback sometimes has crackling and distortion. I thought earlier this was some TX sync issue on sender side, but keeping 1+ packets queued in controller all the time did not solve it. Since also RX appears to miss packets, it's maybe not related to that after all.

This might be hard to figure out without air traces, will need to reproduce it internally.

Quoted 4 lines

(4) The Samsung device has some issue in that disabling source ASEs does not complete. Workaround is to never release transports, but would need to take a look again at this to be sure if it's only device issue.

Make sure you have btmon to collect the traces when this happens.

Quoted 3 lines

(5) Sometimes when connecting one earbud, the other earbud fails to connect. Haven't yet looked into this.

Ive seen that, this may actually be something like:

https://github.com/bluez/bluez/issues/340#issuecomment-1494877679

This is less pronounced when we use the auto-connect list, since that attempts to connect whenever it sees the device advertising so it will continue to attempt multiple times, with the latest bluez tree this is now the default behavior:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/commit/?id=ca07d198f9c7d289e95091c30ed15bff2106a7db

Quoted 13 lines

Because of (2) and (3), I'm not sure now if (1) is general issue or only for this device combination. However, how things are done right now, there doesn't seem to be a way for the user to detect CIS desynchronization or recover from it.

Some things I tried: setting matching sequence numbers to the HCI ISO packets for the two CIS, but doesn't seem to do anything (maybe controller ignores them?). Setting packet timestamps does something, but appears to require synchronizing to the controller clock to produce any audio, which cannot be done since the controller does not have working LE Read ISO TX Sync.

Quoted 6 lines

I also thought that maybe kernel hci_sched_iso could cause it, but at least changing it to send packets to controller in sequence number (provided by PW) order didn't seem to change anything.

So right now at least this TWS device usually works OK, but not yet robustly enough to be non-experimental feature.

Yeah, I think there will be some time needed to mature the stacks and firmware to match what we currently have in Classic, but it is great to have this sort of feedback from the audio subsystem.

Quoted 85 lines

The Intel AX210 problem:

[ 1627.217064] usb 1-5: new full-speed USB device number 16 using xhci_hcd
[ 1627.370401] usb 1-5: New USB device found, idVendor=8087, idProduct=0032, bcdDevice= 0.00
[ 1627.370408] usb 1-5: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 1627.374671] Bluetooth: hci0: Device revision is 0
[ 1627.374676] Bluetooth: hci0: Secure boot is enabled
[ 1627.374678] Bluetooth: hci0: OTP lock is enabled
[ 1627.374680] Bluetooth: hci0: API lock is enabled
[ 1627.374681] Bluetooth: hci0: Debug lock is disabled
[ 1627.374683] Bluetooth: hci0: Minimum firmware build 1 week 10 2014
[ 1627.374685] Bluetooth: hci0: Bootloader timestamp 2019.40 buildtype 1 build 38
[ 1627.410381] Bluetooth: hci0: Found device firmware: intel/ibt-0041-0041.sfi
[ 1627.410446] Bluetooth: hci0: Boot Address: 0x100800
[ 1627.410447] Bluetooth: hci0: Firmware Version: 107-51.22
[ 1629.568723] Bluetooth: hci0: Waiting for firmware download to complete
[ 1629.569770] Bluetooth: hci0: Firmware loaded in 2108786 usecs
[ 1629.570011] Bluetooth: hci0: Waiting for device to boot
[ 1629.595622] Bluetooth: hci0: Device booted in 25187 usecs
[ 1629.595647] Bluetooth: hci0: Malformed MSFT vendor event: 0x02
[ 1629.595923] Bluetooth: hci0: Found Intel DDC parameters: intel/ibt-0041-0041.ddc
[ 1629.597711] Bluetooth: hci0: Applying Intel DDC parameters completed
[ 1629.600707] Bluetooth: hci0: Firmware timestamp 2022.51 buildtype 1 build 56683
[ 1629.677307] Bluetooth: MGMT ver 1.22

< HCI Command: LE Set Connect.. (0x08|0x0062) plen 33 #16903 [hci0] 802.544515

        CIG ID: 0x00
        Central to Peripheral SDU Interval: 10000 us (0x002710)
        Peripheral to Central SDU Interval: 10000 us (0x002710)
        SCA: 201 - 500 ppm (0x00)
        Packing: Sequential (0x00)
        Framing: Unframed (0x00)
        Central to Peripheral Maximum Latency: 20 ms (0x0014)
        Peripheral to Central Maximum Latency: 20 ms (0x0014)
        Number of CIS: 2
        CIS ID: 0x00
        Central to Peripheral Maximum SDU Size: 120
        Peripheral to Central Maximum SDU Size: 120
        Central to Peripheral PHY: LE 2M (0x02)
        Peripheral to Central PHY: LE 2M (0x02)
        Central to Peripheral Retransmission attempts: 0x05
        Peripheral to Central Retransmission attempts: 0x05
        CIS ID: 0x01
        Central to Peripheral Maximum SDU Size: 120
        Peripheral to Central Maximum SDU Size: 120
        Central to Peripheral PHY: LE 2M (0x02)
        Peripheral to Central PHY: LE 2M (0x02)
        Central to Peripheral Retransmission attempts: 0x05
        Peripheral to Central Retransmission attempts: 0x05
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 10 #16904 [hci0] 802.547134

      LE Set Connected Isochronous Group Parameters (0x08|0x0062) ncmd 1
        Status: Success (0x00)
        CIG ID: 0x00
        Number of Handles: 2
        Connection Handle #0: 2560
        Connection Handle #1: 2561
...
< HCI Command: LE Create Conne.. (0x08|0x0064) plen 9  #16928 [hci0] 833.626566
        Number of CIS: 2
        CIS Handle: 2560
        ACL Handle: 3585
        CIS Handle: 2561
        ACL Handle: 3586
Quoted 1 line

HCI Event: Command Status (0x0f) plen 4 #16929 [hci0] 833.628188

      LE Create Connected Isochronous Stream (0x08|0x0064) ncmd 1
        Status: Success (0x00)
Quoted 1 line

HCI Event: LE Meta Event (0x3e) plen 29 #16930 [hci0] 833.670453

      LE Connected Isochronous Stream Established (0x19)
        Status: Unspecified Error (0x1f)
        Connection Handle: 2561
        CIG Synchronization Delay: 89856 us (0x015f00)
        CIS Synchronization Delay: 4718843 us (0x4800fb)
        Central to Peripheral Latency: 1 us (0x000001)
        Peripheral to Central Latency: 0 us (0x000000)
        Central to Peripheral PHY: Reserved (0x00)
        Peripheral to Central PHY: Reserved (0x00)
        Number of Subevents: 0
        Central to Peripheral Burst Number: 0
        Peripheral to Central Burst Number: 0
        Central to Peripheral Flush Timeout: 0
        Peripheral to Central Flush Timeout: 0
        Central to Peripheral MTU: 1536
        Peripheral to Central MTU: 0
        ISO Interval: 10752
Quoted 11 lines

= bluetoothd: profiles/audio/bap.c:iso_connect_cb() connect to 2.. 833.670831

--
Pauli Virtanen

Quoted 3 lines
Quoted 3 lines

[1] https://github.com/pv/linux/commits/iso-fix-multicis
[2] https://github.com/pv/linux/commits/iso-timestamp
[3] https://gitlab.freedesktop.org/pvir/pipewire/-/commits/iso-timestamp-test

Quoted 6 lines

https://gitlab.freedesktop.org/pvir/pipewire/-/commit/667ab3c693e0425568ac405a6a311754ed798653

In the isotest/bluetoothctl we actually use the latency/interval to determine how many packets we have to send at each ISO interval:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/tools/isotest.c#n704

Btw, not sure you if are following the list but I'm working on adding support for handling multiple CIS to the same peer:

https://patchwork.kernel.org/project/bluetooth/list/?series=739574

That should allow you to set a different CIS ID if you want to use different sockets for input and output.

Id also would like to discuss how we do some test automation using pipewire endpoints in the future, we probably want to enable it via test-runner but we probably need to enable it loading pipewire daemons etc under the vm that test-runner creates, Frederic started adding some support but it doesn't look like it loads pipewire so Im not really sure how it supposed to be loaded:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/tools/test-runner.c#n1108
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/tools/test-runner.c#n277

Quoted 2 lines

--
Luiz Augusto von Dentz

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

Hi Luiz,

to, 2023-04-13 kello 11:48 -0700, Luiz Augusto von Dentz kirjoitti:
[clip]

Quoted 7 lines

Btw, not sure you if are following the list but I'm working on adding support for handling multiple CIS to the same peer:

https://patchwork.kernel.org/project/bluetooth/list/?series=739574

That should allow you to set a different CIS ID if you want to use different sockets for input and output.

Great, I saw the patchset but didn't yet have time to take a proper look.

Quoted 9 lines

Id also would like to discuss how we do some test automation using pipewire endpoints in the future, we probably want to enable it via test-runner but we probably need to enable it loading pipewire daemons etc under the vm that test-runner creates, Frederic started adding some support but it doesn't look like it loads pipewire so Im not really sure how it supposed to be loaded:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/tools/test-runner.c#n1108
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/tools/test-runner.c#n277

Yes, there'd be two daemons to start in the VM, pipewire and wireplumber, and running with default config should then result to the endpoints being created.

The interaction is probably simplest via the command-line tools. In principle something more clever and better controlled is possible, but I'd need to think a bit more what's best here.

Output from pw-dump -m can be polled and parsed for determining when daemons are ready, what bluetooth sinks/devices appeared after connect, etc. pw-cat can be used for playback and recording.

Some tests probably can be written along these lines, but without trying now I don't know yet how well the above would work.

A separate question is how the virtual BT device that is going to interact with the endpoints is going to be implemented. Hand-coded data sent via emulator bthost?

Signature · 1 line
Pauli Virtanen
author maintainer
#23 lore raw

Hi Pauli,

Quoted 29 lines · Pauli Virtanen

Hi Luiz,

to, 2023-04-13 kello 11:48 -0700, Luiz Augusto von Dentz kirjoitti:
[clip]

Quoted 7 lines

Btw, not sure you if are following the list but I'm working on adding support for handling multiple CIS to the same peer:

https://patchwork.kernel.org/project/bluetooth/list/?series=739574

That should allow you to set a different CIS ID if you want to use different sockets for input and output.

Great, I saw the patchset but didn't yet have time to take a proper look.

Quoted 9 lines

Id also would like to discuss how we do some test automation using pipewire endpoints in the future, we probably want to enable it via test-runner but we probably need to enable it loading pipewire daemons etc under the vm that test-runner creates, Frederic started adding some support but it doesn't look like it loads pipewire so Im not really sure how it supposed to be loaded:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/tools/test-runner.c#n1108
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/tools/test-runner.c#n277

Yes, there'd be two daemons to start in the VM, pipewire and wireplumber, and running with default config should then result to the endpoints being created.

Quoted 7 lines

The interaction is probably simplest via the command-line tools. In principle something more clever and better controlled is possible, but I'd need to think a bit more what's best here.

Output from pw-dump -m can be polled and parsed for determining when daemons are ready, what bluetooth sinks/devices appeared after connect, etc. pw-cat can be used for playback and recording.

Yep, in terms of tests the ideal solution would be simulate BAP qualification tests:

https://www.bluetooth.org/docman/handlers/DownloadDoc.ashx?doc_id=524716

Ive started to write them as unit tests:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/unit/test-bap.c

It is somewhat laborious to write all the PDUs manually like that but if we managed to write all the tests we could perhaps enable it working with the full stack rather than limiting it bt_bap instance, but perhaps it is overkill since we could instead automate qualification tests via auto-pts.

Quoted 6 lines

Some tests probably can be written along these lines, but without trying now I don't know yet how well the above would work.

A separate question is how the virtual BT device that is going to interact with the endpoints is going to be implemented. Hand-coded data sent via emulator bthost?

We can do both a hand-coded tests with bthost or hook a second instance of btdev to BlueZ so we test BlueZ vs BlueZ, well in theory we could even bring another stack as well like zephyr into the picture, anyway what we need to know is how to setup the environment for pipewire and wireplumber, note that we don't have the so called user session under test-runner environment, so I wonder if we need wireplumber?

Quoted 4 lines

--
Pauli Virtanen

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

pe, 2023-04-14 kello 14:56 -0700, Luiz Augusto von Dentz kirjoitti:

Quoted 62 lines

Hi Pauli,

Quoted 29 lines · Pauli Virtanen

Hi Luiz,

to, 2023-04-13 kello 11:48 -0700, Luiz Augusto von Dentz kirjoitti:
[clip]

Quoted 7 lines

Btw, not sure you if are following the list but I'm working on adding support for handling multiple CIS to the same peer:

https://patchwork.kernel.org/project/bluetooth/list/?series=739574

That should allow you to set a different CIS ID if you want to use different sockets for input and output.

Great, I saw the patchset but didn't yet have time to take a proper look.

Quoted 9 lines

Id also would like to discuss how we do some test automation using pipewire endpoints in the future, we probably want to enable it via test-runner but we probably need to enable it loading pipewire daemons etc under the vm that test-runner creates, Frederic started adding some support but it doesn't look like it loads pipewire so Im not really sure how it supposed to be loaded:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/tools/test-runner.c#n1108
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/tools/test-runner.c#n277

Yes, there'd be two daemons to start in the VM, pipewire and wireplumber, and running with default config should then result to the endpoints being created.

Quoted 7 lines

The interaction is probably simplest via the command-line tools. In principle something more clever and better controlled is possible, but I'd need to think a bit more what's best here.

Output from pw-dump -m can be polled and parsed for determining when daemons are ready, what bluetooth sinks/devices appeared after connect, etc. pw-cat can be used for playback and recording.

Yep, in terms of tests the ideal solution would be simulate BAP qualification tests:

https://www.bluetooth.org/docman/handlers/DownloadDoc.ashx?doc_id=524716

Ive started to write them as unit tests:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/unit/test-bap.c

It is somewhat laborious to write all the PDUs manually like that but if we managed to write all the tests we could perhaps enable it working with the full stack rather than limiting it bt_bap instance, but perhaps it is overkill since we could instead automate qualification tests via auto-pts.

Quoted 7 lines

Some tests probably can be written along these lines, but without trying now I don't know yet how well the above would work.

A separate question is how the virtual BT device that is going to interact with the endpoints is going to be implemented. Hand-coded data sent via emulator bthost?

Quoted 7 lines

We can do both a hand-coded tests with bthost or hook a second instance of btdev to BlueZ so we test BlueZ vs BlueZ, well in theory we could even bring another stack as well like zephyr into the picture, anyway what we need to know is how to setup the environment for pipewire and wireplumber, note that we don't have the so called user session under test-runner environment, so I wonder if we need wireplumber?

I sent an example patch to the list that adds an option to launch PW with tools/test-runner so that you get the endpoints registered. You have to disable a few things for it to run in plain environment (ALSA device reservations and flatpak portal want DBus user session, logind integration wants logind).

The "session manager" is some JACK terminology, not really related to user sessions, in PW it is what coordinates audio device discovery, and connects clients to devices, so you have to run one.

Signature · 1 line
Pauli Virtanen
#25 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 4 lines

Hi Pauli,

Quoted 1 line · Pauli Virtanen

ke, 2023-04-05 kello 17:16 -0700, Luiz Augusto von Dentz kirjoitti:

[clip]

Quoted 32 lines
Quoted 26 lines
Quoted 4 lines
Quoted 1 line

[0] https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1564

Did you make any progress on these changes above? Looks like the pull request is still open, I wonder if you hit some blocker?

The device set part is fine now.

However, I've been first looking at sorting out TWS playback synchronization, and ran to some issues there.

Current laundry list:

(1) The playback to the left/right earbuds can rarely desynchronize spontaneously during playback, even though we send packets to both ISO socket fds at the same time on ISO interval schedule.

Possibly, it goes to a state where the two CIS are off by one packet due to some queue on controller side. Desynchronization by 10ms can be heard easily in TWS earbuds as it transforms click at stereo center to separate clicks on left and right as brain interprets it.

It usually resynchronizes if we halt sending packets to both CIS for ~ 50+ ms and then continue, and sometimes it resynchronizes spontaneously.

Quoted 5 lines

I've been looking at the conn->sent values at packet completion event time, but it is not clear it's possible to distinguish the desynchronized state from synchronized one, as it appears in both you can have either 0 or 1 and occasionally 2 packets not yet acked by the controller.

Quoted 4 lines

Interesting, what is the presentation delay configured, in theory that should be used to synchronize the streams, we may need a way to measure this latency and attempt to compensate for it somehow if transfer speed variates.

The presentation delay is configured as 40ms, the device also reports max=min=40ms limits for the delay.

The CIG configuration is

< HCI Command: LE Set Connected.. (0x08|0x0062) plen 33 #686 [hci1]

    CIG ID: 0x00
    Central to Peripheral SDU Interval: 10000 us (0x002710)
    Peripheral to Central SDU Interval: 10000 us (0x002710)
    SCA: 201 - 500 ppm (0x00)
    Packing: Sequential (0x00)
    Framing: Unframed (0x00)
    Central to Peripheral Maximum Latency: 100 ms (0x0064)
    Peripheral to Central Maximum Latency: 100 ms (0x0064)
    Number of CIS: 2
    CIS ID: 0x00
    Central to Peripheral Maximum SDU Size: 120
    Peripheral to Central Maximum SDU Size: 120
    Central to Peripheral PHY: LE 2M (0x02)
    Peripheral to Central PHY: LE 2M (0x02)
    Central to Peripheral Retransmission attempts: 0x05
    Peripheral to Central Retransmission attempts: 0x05
    CIS ID: 0x01
    Central to Peripheral Maximum SDU Size: 120
    Peripheral to Central Maximum SDU Size: 120
    Central to Peripheral PHY: LE 2M (0x02)
    Peripheral to Central PHY: LE 2M (0x02)
    Central to Peripheral Retransmission attempts: 0x05
    Peripheral to Central Retransmission attempts: 0x05

Sometimes the desynchronization appears immediately after connect, or randomly during playback. It can also be part of the time be triggered by walking away from the transmitter, or covering the earpieces by hands until it starts to stutter. This last one is the most reliable reproducer, but still not high success rate so a bit hard to debug.

In one case this persisted also over device disconnect + reconnect.

From the ISO socket user side, nothing unusual seems to happen, all writes succeed so we're not dropping data. In one case I checked where the playback was desynchronized after start, we were writing to both sockets every 10ms with max +-0.2ms jitter.

Not sure how to debug this further right now. Maybe should check with different devices.

Quoted 10 lines
Quoted 5 lines

(2) With the Samsung device, Intel AX210 fails LE Create CIS for the CIG with both earbuds with current kernel (btmon logs below). It works if only one device is connected. As a workaround, I'm currently using a patch [1] that changes it to do LE Create CIS for the CIG one by one. Since that works, could be some controller issue.

I believe we fixed that, are you running with the latest firmware and bluetooth-next? On the kernel side you may need the following:

https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/commit/?id=70eff70d453bdb529d8233f59e32c1ffedac7685

I missed that patch, seems to work fine with it.

Quoted 9 lines
Quoted 6 lines

(3) The playback from Intel AX210 -> Samsung device apparently has some issue with the radio link/etc, as playback sometimes has crackling and distortion. I thought earlier this was some TX sync issue on sender side, but keeping 1+ packets queued in controller all the time did not solve it. Since also RX appears to miss packets, it's maybe not related to that after all.

This might be hard to figure out without air traces, will need to reproduce it internally.

This might be partly due to bad QoS.

good:

< HCI Command: LE Set Connected.. (0x08|0x0062) plen 33 #686 [hci1]
...
Central to Peripheral Maximum Latency: 100 ms (0x0064) Peripheral to Central Maximum Latency: 100 ms (0x0064)

bad:

< HCI Command: LE Set Connected.. (0x08|0x0062) plen 33 #862 [hci1]
...
Central to Peripheral Maximum Latency: 20 ms (0x0014) Peripheral to Central Maximum Latency: 20 ms (0x0014)

In the "good" case there is sometimes crackling, but in the "bad" case it's continuous.

However, also in the "good" case it seems we are not receiving all RX packets we should get. The average RX rate in btmon seems to be 183 packets/s for two devices instead of 200/s. (Suspiciously close to 200*44100/48000...)

The "bad" case occurred because BlueZ does not pass the Latency parameter (or any other QoS parameters) to SelectProperties if it has not connected to the device before, so we ended up configuring the QoS with low-latency value from BAP Table 5.2, which apparently the devices couldn't handle. (I switched this now to use the "high-reliability" values from the table as fallback, but it's a workaround.)

IIUC the max latency is supposed to be configured as

1. Target_Latency -> Config Codec -> Max_Transport_Latency
2. select good Max_Transport_Latency -> Config QoS

Currently SelectProperties is supposed to select QoS parameters, but it is called before Config Codec, so Max_Transport_Latency, preferred Presentation_Delay, etc. are not known at that time if bluez didn't cache them somewhere.

I see there are some TODOs in BlueZ sources on this, so looks like known issue.

Quoted 5 lines
Quoted 3 lines

(4) The Samsung device has some issue in that disabling source ASEs does not complete. Workaround is to never release transports, but would need to take a look again at this to be sure if it's only device issue.

Make sure you have btmon to collect the traces when this happens.

I'll try to come back to this.

Quoted 135 lines
Quoted 2 lines

(5) Sometimes when connecting one earbud, the other earbud fails to connect. Haven't yet looked into this.

Ive seen that, this may actually be something like:

https://github.com/bluez/bluez/issues/340#issuecomment-1494877679

This is less pronounced when we use the auto-connect list, since that attempts to connect whenever it sees the device advertising so it will continue to attempt multiple times, with the latest bluez tree this is now the default behavior:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/commit/?id=ca07d198f9c7d289e95091c30ed15bff2106a7db

Quoted 13 lines

Because of (2) and (3), I'm not sure now if (1) is general issue or only for this device combination. However, how things are done right now, there doesn't seem to be a way for the user to detect CIS desynchronization or recover from it.

Some things I tried: setting matching sequence numbers to the HCI ISO packets for the two CIS, but doesn't seem to do anything (maybe controller ignores them?). Setting packet timestamps does something, but appears to require synchronizing to the controller clock to produce any audio, which cannot be done since the controller does not have working LE Read ISO TX Sync.

Quoted 6 lines

I also thought that maybe kernel hci_sched_iso could cause it, but at least changing it to send packets to controller in sequence number (provided by PW) order didn't seem to change anything.

So right now at least this TWS device usually works OK, but not yet robustly enough to be non-experimental feature.

Yeah, I think there will be some time needed to mature the stacks and firmware to match what we currently have in Classic, but it is great to have this sort of feedback from the audio subsystem.

Quoted 85 lines

The Intel AX210 problem:

[ 1627.217064] usb 1-5: new full-speed USB device number 16 using xhci_hcd
[ 1627.370401] usb 1-5: New USB device found, idVendor=8087, idProduct=0032, bcdDevice= 0.00
[ 1627.370408] usb 1-5: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 1627.374671] Bluetooth: hci0: Device revision is 0
[ 1627.374676] Bluetooth: hci0: Secure boot is enabled
[ 1627.374678] Bluetooth: hci0: OTP lock is enabled
[ 1627.374680] Bluetooth: hci0: API lock is enabled
[ 1627.374681] Bluetooth: hci0: Debug lock is disabled
[ 1627.374683] Bluetooth: hci0: Minimum firmware build 1 week 10 2014
[ 1627.374685] Bluetooth: hci0: Bootloader timestamp 2019.40 buildtype 1 build 38
[ 1627.410381] Bluetooth: hci0: Found device firmware: intel/ibt-0041-0041.sfi
[ 1627.410446] Bluetooth: hci0: Boot Address: 0x100800
[ 1627.410447] Bluetooth: hci0: Firmware Version: 107-51.22
[ 1629.568723] Bluetooth: hci0: Waiting for firmware download to complete
[ 1629.569770] Bluetooth: hci0: Firmware loaded in 2108786 usecs
[ 1629.570011] Bluetooth: hci0: Waiting for device to boot
[ 1629.595622] Bluetooth: hci0: Device booted in 25187 usecs
[ 1629.595647] Bluetooth: hci0: Malformed MSFT vendor event: 0x02
[ 1629.595923] Bluetooth: hci0: Found Intel DDC parameters: intel/ibt-0041-0041.ddc
[ 1629.597711] Bluetooth: hci0: Applying Intel DDC parameters completed
[ 1629.600707] Bluetooth: hci0: Firmware timestamp 2022.51 buildtype 1 build 56683
[ 1629.677307] Bluetooth: MGMT ver 1.22

< HCI Command: LE Set Connect.. (0x08|0x0062) plen 33 #16903 [hci0] 802.544515

        CIG ID: 0x00
        Central to Peripheral SDU Interval: 10000 us (0x002710)
        Peripheral to Central SDU Interval: 10000 us (0x002710)
        SCA: 201 - 500 ppm (0x00)
        Packing: Sequential (0x00)
        Framing: Unframed (0x00)
        Central to Peripheral Maximum Latency: 20 ms (0x0014)
        Peripheral to Central Maximum Latency: 20 ms (0x0014)
        Number of CIS: 2
        CIS ID: 0x00
        Central to Peripheral Maximum SDU Size: 120
        Peripheral to Central Maximum SDU Size: 120
        Central to Peripheral PHY: LE 2M (0x02)
        Peripheral to Central PHY: LE 2M (0x02)
        Central to Peripheral Retransmission attempts: 0x05
        Peripheral to Central Retransmission attempts: 0x05
        CIS ID: 0x01
        Central to Peripheral Maximum SDU Size: 120
        Peripheral to Central Maximum SDU Size: 120
        Central to Peripheral PHY: LE 2M (0x02)
        Peripheral to Central PHY: LE 2M (0x02)
        Central to Peripheral Retransmission attempts: 0x05
        Peripheral to Central Retransmission attempts: 0x05
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 10 #16904 [hci0] 802.547134

      LE Set Connected Isochronous Group Parameters (0x08|0x0062) ncmd 1
        Status: Success (0x00)
        CIG ID: 0x00
        Number of Handles: 2
        Connection Handle #0: 2560
        Connection Handle #1: 2561
...
< HCI Command: LE Create Conne.. (0x08|0x0064) plen 9  #16928 [hci0] 833.626566
        Number of CIS: 2
        CIS Handle: 2560
        ACL Handle: 3585
        CIS Handle: 2561
        ACL Handle: 3586
Quoted 1 line

HCI Event: Command Status (0x0f) plen 4 #16929 [hci0] 833.628188

      LE Create Connected Isochronous Stream (0x08|0x0064) ncmd 1
        Status: Success (0x00)
Quoted 1 line

HCI Event: LE Meta Event (0x3e) plen 29 #16930 [hci0] 833.670453

      LE Connected Isochronous Stream Established (0x19)
        Status: Unspecified Error (0x1f)
        Connection Handle: 2561
        CIG Synchronization Delay: 89856 us (0x015f00)
        CIS Synchronization Delay: 4718843 us (0x4800fb)
        Central to Peripheral Latency: 1 us (0x000001)
        Peripheral to Central Latency: 0 us (0x000000)
        Central to Peripheral PHY: Reserved (0x00)
        Peripheral to Central PHY: Reserved (0x00)
        Number of Subevents: 0
        Central to Peripheral Burst Number: 0
        Peripheral to Central Burst Number: 0
        Central to Peripheral Flush Timeout: 0
        Peripheral to Central Flush Timeout: 0
        Central to Peripheral MTU: 1536
        Peripheral to Central MTU: 0
        ISO Interval: 10752
Quoted 11 lines

= bluetoothd: profiles/audio/bap.c:iso_connect_cb() connect to 2.. 833.670831

--
Pauli Virtanen

Quoted 3 lines
Quoted 3 lines

[1] https://github.com/pv/linux/commits/iso-fix-multicis
[2] https://github.com/pv/linux/commits/iso-timestamp
[3] https://gitlab.freedesktop.org/pvir/pipewire/-/commits/iso-timestamp-test

Quoted 6 lines

https://gitlab.freedesktop.org/pvir/pipewire/-/commit/667ab3c693e0425568ac405a6a311754ed798653

In the isotest/bluetoothctl we actually use the latency/interval to determine how many packets we have to send at each ISO interval:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/tools/isotest.c#n704

In realtime context it seems what isotest.c does (or intends to --- does it actually skip the first sleep to have extra packets queued in controller?) probably is equivalent to pushing num extra packets of silence to the socket when playback starts.

Looking at Core v5.3, Part G, Fig 3.2, it seems to me this increases latency by the number of extra packets pushed, on top of the transport latency. If it is so, I think we'd like to use as few as possible or none.

OTOH, if the statement is that we should write num=latency/interval packets every num intervals, I don't quite understand why, and it seems also this should increase latency because we need to gather all that audio data before we can send it to the socket?

Signature · 1 line
Pauli Virtanen