Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ v1 0/4] shared/bap: Don't disconnect a CIS still used by another ASE
@ 2026-11-10 22:18 Luiz Augusto von Dentz
  2026-11-10 22:18 ` [PATCH BlueZ v1 1/4] shared/bap: Don't disconnect a CIS still configured for a link Luiz Augusto von Dentz
                   ` (13 more replies)
  0 siblings, 14 replies; 29+ messages in thread
From: Luiz Augusto von Dentz @ 2026-11-10 22:18 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

A remote initiator, e.g. a phone in a voice call, may enable the Source
ASE of a CIS shared with a Sink ASE and then switch to the Sink ASE
alone. The acceptor disconnected the CIS when the Source ASE detached
from it, although the linked Sink ASE was still configured for it, and
as the initiator does not request the CIS again, the Sink ASE was left
enabled without a CIS and the voice stayed silent.

Keep the CIS while another ASE is still configured for it. Unit tests
cover releasing an ASE of a CIS kept by its link, of a shared CIS and
switching the direction, and a functional test counts the CIS the
acceptor is asked to accept.

Luiz Augusto von Dentz (4):
  shared/bap: Don't disconnect a CIS still configured for a link
  unit/test-bap: Add tests for a CIS shared by two ASEs
  doc/functional-bap: Document switching the direction of a CIS
  test: functional: Cover switching the direction of a CIS

 doc/functional-bap.rst      |  37 ++++++
 src/shared/bap.c            |  84 +++++++++----
 test/functional/test_bap.py |  68 +++++++++++
 unit/test-bap.c             | 227 ++++++++++++++++++++++++++++++++++++
 4 files changed, 391 insertions(+), 25 deletions(-)

-- 
2.56.0


^ permalink raw reply	[flat|nested] 29+ messages in thread
* [PATCH BlueZ v2 2/2] unit: Test HoG report map reads after reconnect
@ 2026-09-25 22:03 Giuseppe Piscitelli
  2026-10-11  1:20 ` None bluez.test.bot
  0 siblings, 1 reply; 29+ messages in thread
From: Giuseppe Piscitelli @ 2026-09-25 22:03 UTC (permalink / raw)
  To: linux-bluetooth

From: Giuseppe Piscitelli <35407790+ooonea@users.noreply.github.com>

Exercise reconnect after an ATT error and after cancelling a pending
Report Map read. Require a fresh read and validate the resulting
UHID_CREATE2 descriptor on a simulated transport.

Stub Bluetooth address lookup for the Unix socketpair fixture. Both
cases fail without resetting report_map_id on detach.

Assisted-by: OpenAI Codex:gpt-6
---
v2: Resend without quoted email history; code unchanged.

 Makefile.am     |   2 +-
 unit/test-hog.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 140 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 1d46b9b..1621794 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -767,7 +767,7 @@ unit_test_gatt_LDADD = src/libshared-glib.la \
 unit_tests += unit/test-hog

 unit_test_hog_SOURCES = unit/test-hog.c \
-			$(btio_sources) \
+			btio/btio.h \
 			profiles/input/hog-lib.h profiles/input/hog-lib.c \
 			profiles/scanparam/scpp.h profiles/scanparam/scpp.c \
 			profiles/battery/bas.h profiles/battery/bas.c \
diff --git a/unit/test-hog.c b/unit/test-hog.c
index 45ffe71..405af8a 100644
--- a/unit/test-hog.c
+++ b/unit/test-hog.c
@@ -17,6 +17,8 @@
 #include <string.h>
 #include <sys/socket.h>
 #include <fcntl.h>
+#include <stdarg.h>
+#include <linux/uhid.h>

 #include <glib.h>

@@ -30,9 +32,28 @@
 #include "src/shared/gatt-db.h"

 #include "attrib/gattrib.h"
+#include "btio/btio.h"

 #include "profiles/input/hog-lib.h"

+gboolean bt_io_get(GIOChannel *io, GError **error, BtIOOption opt, ...)
+{
+	va_list args;
+
+	va_start(args, opt);
+
+	while (opt != BT_IO_OPT_INVALID) {
+		g_assert(opt == BT_IO_OPT_SOURCE_BDADDR ||
+					opt == BT_IO_OPT_DEST_BDADDR);
+		memset(va_arg(args, bdaddr_t *), 0, sizeof(bdaddr_t));
+		opt = va_arg(args, int);
+	}
+
+	va_end(args);
+
+	return TRUE;
+}
+
 struct test_pdu {
 	bool valid;
 	const uint8_t *data;
@@ -211,10 +232,128 @@ static void test_hog(gconstpointer data)
 	g_assert(bt_hog_attach(context->hog, context->attrib));
 }

+static ssize_t receive(int fd, void *buf, size_t size)
+{
+	gint64 deadline = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
+	ssize_t len;
+
+	do {
+		while (g_main_context_iteration(NULL, FALSE))
+			;
+
+		len = recv(fd, buf, size, MSG_DONTWAIT);
+		if (len >= 0)
+			return len;
+
+		g_usleep(1000);
+	} while (g_get_monotonic_time() < deadline);
+
+	return -1;
+}
+
+static void expect_read(int fd, uint8_t handle)
+{
+	uint8_t buf[32];
+	ssize_t len = receive(fd, buf, sizeof(buf));
+
+	g_assert_cmpint(len, ==, 3);
+	g_assert_cmpuint(buf[0], ==, BT_ATT_OP_READ_REQ);
+	g_assert_cmpuint(buf[1], ==, handle);
+	g_assert_cmpuint(buf[2], ==, 0);
+}
+
+static void respond(int fd, const void *buf, size_t size)
+{
+	g_assert_cmpint(send(fd, buf, size, 0), ==, size);
+}
+
+static void test_reconnect(gconstpointer data)
+{
+	const uint8_t info[] = { 0x0b, 0x11, 0x01, 0x00, 0x00 };
+	const uint8_t error[] = { 0x01, 0x0a, 0x05, 0x00, 0x0e };
+	const uint8_t map[] = { 0x0b, 0x05, 0x01, 0x09, 0x02, 0xa1, 0x01,
+				0x09, 0x30, 0x15, 0x81, 0x25, 0x7f, 0x75,
+				0x08, 0x95, 0x01, 0x81, 0x06, 0xc0 };
+	struct gatt_db *db = gatt_db_new();
+	struct gatt_db_attribute *service;
+	struct bt_hog *hog;
+	struct uhid_event ev;
+	GIOChannel *channel;
+	GAttrib *attrib;
+	bt_uuid_t uuid;
+	int att[2], uhid[2];
+	bool cancel = GPOINTER_TO_INT(data);
+
+	g_assert_cmpint(socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK,
+							0, att), ==, 0);
+	g_assert_cmpint(socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK,
+							0, uhid), ==, 0);
+	bt_uuid16_create(&uuid, 0x1812);
+	service = gatt_db_add_service(db, &uuid, true, 5);
+	g_assert(service);
+	bt_uuid16_create(&uuid, 0x2a4a);
+	g_assert(gatt_db_service_add_characteristic(service, &uuid,
+				BT_ATT_PERM_READ, 0x02, NULL, NULL, NULL));
+	bt_uuid16_create(&uuid, 0x2a4b);
+	g_assert(gatt_db_service_add_characteristic(service, &uuid,
+				BT_ATT_PERM_READ, 0x02, NULL, NULL, NULL));
+	gatt_db_service_set_active(service, true);
+	channel = g_io_channel_unix_new(att[0]);
+	g_io_channel_set_close_on_unref(channel, TRUE);
+	attrib = g_attrib_new(channel, 23, false);
+	g_io_channel_unref(channel);
+	hog = bt_hog_new(uhid[0], "report-map-test", 1, 1, 1, 0, db);
+	g_assert(hog);
+	g_assert(bt_hog_attach(hog, attrib));
+	expect_read(att[1], 3);
+	respond(att[1], info, sizeof(info));
+	expect_read(att[1], 5);
+
+	if (!cancel) {
+		respond(att[1], error, sizeof(error));
+
+		while (g_main_context_iteration(NULL, FALSE))
+			;
+	}
+
+	bt_hog_detach(hog, false);
+	g_attrib_unref(attrib);
+	close(att[1]);
+	g_assert_cmpint(socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK,
+							0, att), ==, 0);
+	channel = g_io_channel_unix_new(att[0]);
+	g_io_channel_set_close_on_unref(channel, TRUE);
+	attrib = g_attrib_new(channel, 23, false);
+	g_io_channel_unref(channel);
+	g_assert(bt_hog_attach(hog, attrib));
+	expect_read(att[1], 3);
+	respond(att[1], info, sizeof(info));
+	expect_read(att[1], 5);
+	respond(att[1], map, sizeof(map));
+	g_assert_cmpint(receive(uhid[1], &ev, sizeof(ev)), ==, sizeof(ev));
+	g_assert_cmpuint(ev.type, ==, UHID_CREATE2);
+	g_assert_cmpuint(ev.u.create2.rd_size, ==, sizeof(map) - 1);
+	g_assert_cmpmem(ev.u.create2.rd_data, ev.u.create2.rd_size,
+						map + 1, sizeof(map) - 1);
+	bt_hog_detach(hog, true);
+	bt_hog_unref(hog);
+	g_attrib_unref(attrib);
+	gatt_db_unref(db);
+	close(att[1]);
+	close(uhid[0]);
+	close(uhid[1]);
+	tester_test_passed();
+}
+
 int main(int argc, char *argv[])
 {
 	tester_init(&argc, &argv);

+	tester_add("/hog/report-map/error-reconnect", GINT_TO_POINTER(false),
+					NULL, test_reconnect, NULL);
+	tester_add("/hog/report-map/cancel-reconnect", GINT_TO_POINTER(true),
+					NULL, test_reconnect, NULL);
+
 	define_test("/TP/HGRF/RH/BV-01-I", test_hog,
 		raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
 		raw_pdu(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x12,

^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2026-11-26  4:30 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-10 22:18 [PATCH BlueZ v1 0/4] shared/bap: Don't disconnect a CIS still used by another ASE Luiz Augusto von Dentz
2026-11-10 22:18 ` [PATCH BlueZ v1 1/4] shared/bap: Don't disconnect a CIS still configured for a link Luiz Augusto von Dentz
2026-11-11  4:35   ` shared/bap: Don't disconnect a CIS still used by another ASE bluez.test.bot
2026-11-10 22:19 ` [PATCH BlueZ v1 2/4] unit/test-bap: Add tests for a CIS shared by two ASEs Luiz Augusto von Dentz
2026-11-10 22:19 ` [PATCH BlueZ v1 3/4] doc/functional-bap: Document switching the direction of a CIS Luiz Augusto von Dentz
2026-11-10 22:19 ` [PATCH BlueZ v1 4/4] test: functional: Cover " Luiz Augusto von Dentz
2026-11-10 22:19 ` [PATCH BlueZ v1 0/5] bap: Release cached ASEs on ClearConfiguration Luiz Augusto von Dentz
2026-11-10 22:19   ` [PATCH BlueZ v1 1/5] shared/bap: Add bt_bap_foreach_stream and bt_bap_stream_get_rpac Luiz Augusto von Dentz
2026-11-10 22:19   ` [PATCH BlueZ v1 2/5] bap: Release cached ASEs on ClearConfiguration of an endpoint Luiz Augusto von Dentz
2026-11-10 22:19   ` [PATCH BlueZ v1 3/5] client/player: Add endpoint.clear command Luiz Augusto von Dentz
2026-11-10 22:19   ` [PATCH BlueZ v1 4/5] doc/functional-bap: Document clearing a cached configuration Luiz Augusto von Dentz
2026-11-10 22:19   ` [PATCH BlueZ v1 5/5] test: functional: Cover " Luiz Augusto von Dentz
2026-11-10 22:19 ` [PATCH BlueZ v1 0/8] transport: Hand the owner over to a link still streaming Luiz Augusto von Dentz
2026-11-10 22:19 ` [PATCH BlueZ v1 1/8] " Luiz Augusto von Dentz
2026-11-11  4:23   ` [BlueZ,v1,1/8] " bluez.test.bot
2026-11-26  4:30   ` bluez.test.bot
2026-11-10 22:19 ` [PATCH BlueZ v1 2/8] unit/test-bap: Add test for disabling one ASE of a shared CIS Luiz Augusto von Dentz
2026-11-11  3:05   ` [BlueZ,v1,2/8] " bluez.test.bot
2026-11-16 17:50   ` [PATCH BlueZ v1 2/8] " patchwork-bot+bluetooth
2026-11-10 22:19 ` [PATCH BlueZ v1 3/8] transport: Clear the owner of desynchronized links when removing it Luiz Augusto von Dentz
2026-11-26  4:30   ` None bluez.test.bot
2026-11-10 22:19 ` [PATCH BlueZ v1 4/8] transport: Don't hand the owner over while releasing Luiz Augusto von Dentz
2026-11-11  3:05   ` [BlueZ,v1,4/8] " bluez.test.bot
2026-11-16 17:50   ` [PATCH BlueZ v1 4/8] " patchwork-bot+bluetooth
2026-11-10 22:19 ` [PATCH BlueZ v1 5/8] doc/functional-bap: Document disabling one ASE of a shared owner Luiz Augusto von Dentz
2026-11-10 22:19 ` [PATCH BlueZ v1 6/8] test: functional: Cover " Luiz Augusto von Dentz
2026-11-10 22:19 ` [PATCH BlueZ v1 7/8] doc/functional-bap: Document releasing " Luiz Augusto von Dentz
2026-11-10 22:19 ` [PATCH BlueZ v1 8/8] test: functional: Cover " Luiz Augusto von Dentz
  -- strict thread matches above, loose matches on Subject: below --
2026-09-25 22:03 [PATCH BlueZ v2 2/2] unit: Test HoG report map reads after reconnect Giuseppe Piscitelli
2026-10-11  1:20 ` None bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox