public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] client/btpclient: Add BTP_OP_BAP_DISCOVER support
@ 2026-04-16 18:49 Frédéric Danis
  2026-04-16 20:29 ` [BlueZ] " bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Frédéric Danis @ 2026-04-16 18:49 UTC (permalink / raw)
  To: linux-bluetooth

BAP/CL/CGGIT/SER/BV-01-C expects IUT to discover the services before
continuation.

This reduces connection time for the BAP tests.
---
 Makefile.tools          |   1 +
 client/btpclient/bap.c  | 109 ++++++++++++++++++++++++++++++++++++++++
 client/btpclient/bap.h  |  13 +++++
 client/btpclient/core.c |  15 ++++++
 src/shared/btp.h        |  16 ++++++
 5 files changed, 154 insertions(+)
 create mode 100644 client/btpclient/bap.c
 create mode 100644 client/btpclient/bap.h

diff --git a/Makefile.tools b/Makefile.tools
index 8e0eae04e..001d0129f 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -562,6 +562,7 @@ noinst_PROGRAMS += client/btpclient/btpclient client/btpclient/btpclientctl
 client_btpclient_btpclient_SOURCES = client/btpclient/btpclient.c \
 				client/btpclient/btpclient.h \
 				src/shared/btp.c src/shared/btp.h \
+				client/btpclient/bap.c client/btpclient/bap.h \
 				client/btpclient/core.c client/btpclient/core.h \
 				client/btpclient/gap.c client/btpclient/gap.h \
 				client/btpclient/gatt.c client/btpclient/gatt.h
diff --git a/client/btpclient/bap.c b/client/btpclient/bap.c
new file mode 100644
index 000000000..d64828894
--- /dev/null
+++ b/client/btpclient/bap.c
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2026  Collabora Ltd.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+
+#include <ell/ell.h>
+
+#include "bluetooth/bluetooth.h"
+#include "bluetooth/uuid.h"
+#include "src/shared/btp.h"
+#include "btpclient.h"
+#include "bap.h"
+
+static struct btp *btp;
+static bool bap_service_registered;
+
+static void btp_bap_read_commands(uint8_t index, const void *param,
+					uint16_t length, void *user_data)
+{
+	uint16_t commands = 0;
+
+	if (index != BTP_INDEX_NON_CONTROLLER) {
+		btp_send_error(btp, BTP_BAP_SERVICE, index,
+						BTP_ERROR_INVALID_INDEX);
+		return;
+	}
+
+	commands |= (1 << BTP_OP_BAP_READ_SUPPORTED_COMMANDS);
+	commands |= (1 << BTP_OP_BAP_DISCOVER);
+
+	commands = L_CPU_TO_LE16(commands);
+
+	btp_send(btp, BTP_BAP_SERVICE, BTP_OP_BAP_READ_SUPPORTED_COMMANDS,
+			BTP_INDEX_NON_CONTROLLER, sizeof(commands), &commands);
+}
+
+static void btp_bap_discover(uint8_t index, const void *param, uint16_t length,
+								void *user_data)
+{
+	struct btp_adapter *adapter = find_adapter_by_index(index);
+	const struct btp_bap_discover_cp *cp = param;
+	uint8_t status = BTP_ERROR_FAIL;
+	struct btp_device *dev;
+	struct btp_bap_discovery_completed_ev ev;
+	bool prop;
+
+	if (!adapter) {
+		status = BTP_ERROR_INVALID_INDEX;
+		goto failed;
+	}
+
+	btp_send(btp, BTP_BAP_SERVICE, BTP_OP_BAP_DISCOVER, index, 0, NULL);
+
+	dev = find_device_by_address(adapter, &cp->address, cp->address_type);
+
+	/* Services should have been resolved during connection */
+	if (!l_dbus_proxy_get_property(dev->proxy, "ServicesResolved", "b",
+					&prop) || !prop)
+		goto failed;
+
+	memcpy(&ev.address, &dev->address, sizeof(ev.address));
+	ev.address_type = dev->address_type;
+	ev.status = 0;
+
+	btp_send(btp, BTP_BAP_SERVICE, BTP_EV_BAP_DISCOVERY_COMPLETED,
+			adapter->index, sizeof(ev), &ev);
+
+	return;
+
+failed:
+	btp_send_error(btp, BTP_BAP_SERVICE, index, status);
+}
+
+bool bap_register_service(struct btp *btp_, struct l_dbus *dbus_,
+					struct l_dbus_client *client)
+{
+	btp = btp_;
+
+	btp_register(btp, BTP_BAP_SERVICE, BTP_OP_BAP_READ_SUPPORTED_COMMANDS,
+					btp_bap_read_commands, NULL, NULL);
+
+	btp_register(btp, BTP_BAP_SERVICE, BTP_OP_BAP_DISCOVER,
+					btp_bap_discover, NULL, NULL);
+
+	bap_service_registered = true;
+
+	return true;
+}
+
+void bap_unregister_service(struct btp *btp)
+{
+	btp_unregister_service(btp, BTP_BAP_SERVICE);
+	bap_service_registered = false;
+}
+
+bool bap_is_service_registered(void)
+{
+	return bap_service_registered;
+}
diff --git a/client/btpclient/bap.h b/client/btpclient/bap.h
new file mode 100644
index 000000000..2b7a218b5
--- /dev/null
+++ b/client/btpclient/bap.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2026  Collabora Ltd.
+ *
+ */
+
+bool bap_register_service(struct btp *btp_, struct l_dbus *dbus_,
+					struct l_dbus_client *client);
+void bap_unregister_service(struct btp *btp);
+bool bap_is_service_registered(void);
diff --git a/client/btpclient/core.c b/client/btpclient/core.c
index cfff131f1..772178670 100644
--- a/client/btpclient/core.c
+++ b/client/btpclient/core.c
@@ -13,6 +13,7 @@
 #include "bluetooth/uuid.h"
 #include "src/shared/btp.h"
 #include "btpclient.h"
+#include "bap.h"
 #include "core.h"
 #include "gap.h"
 #include "gatt.h"
@@ -89,6 +90,14 @@ static void btp_core_register(uint8_t index, const void *param,
 		if (!gatt_register_service(btp, dbus, client))
 			goto failed;
 
+		break;
+	case BTP_BAP_SERVICE:
+		if (bap_is_service_registered())
+			goto failed;
+
+		if (!bap_register_service(btp, dbus, client))
+			goto failed;
+
 		break;
 	case BTP_L2CAP_SERVICE:
 	case BTP_MESH_NODE_SERVICE:
@@ -132,6 +141,12 @@ static void btp_core_unregister(uint8_t index, const void *param,
 
 		gatt_unregister_service(btp);
 		break;
+	case BTP_BAP_SERVICE:
+		if (!bap_is_service_registered())
+			goto failed;
+
+		bap_unregister_service(btp);
+		break;
 	case BTP_L2CAP_SERVICE:
 	case BTP_MESH_NODE_SERVICE:
 	case BTP_CORE_SERVICE:
diff --git a/src/shared/btp.h b/src/shared/btp.h
index 8b5078f82..c23346f4e 100644
--- a/src/shared/btp.h
+++ b/src/shared/btp.h
@@ -26,6 +26,7 @@
 #define BTP_GATT_SERVICE	2
 #define BTP_L2CAP_SERVICE	3
 #define BTP_MESH_NODE_SERVICE	4
+#define BTP_BAP_SERVICE		14
 
 struct btp_hdr {
 	uint8_t service;
@@ -344,6 +345,21 @@ struct btp_gatt_write_rp {
 	uint8_t att_response;
 } __packed;
 
+#define BTP_OP_BAP_READ_SUPPORTED_COMMANDS	0x01
+
+#define BTP_OP_BAP_DISCOVER			0x02
+struct btp_bap_discover_cp {
+	uint8_t address_type;
+	bdaddr_t address;
+} __packed;
+
+#define BTP_EV_BAP_DISCOVERY_COMPLETED		0x80
+struct btp_bap_discovery_completed_ev {
+	uint8_t address_type;
+	bdaddr_t address;
+	uint8_t status;
+} __packed;
+
 struct btp;
 
 typedef void (*btp_destroy_func_t)(void *user_data);
-- 
2.43.0


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

end of thread, other threads:[~2026-04-16 20:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-16 18:49 [PATCH BlueZ] client/btpclient: Add BTP_OP_BAP_DISCOVER support Frédéric Danis
2026-04-16 20:29 ` [BlueZ] " 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