All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 4/8] client/btpclient: Add BTP_OP_PACS_SET_LOCATION support
Date: Tue,  8 Sep 2026 19:06:29 +0200	[thread overview]
Message-ID: <20260908170633.510244-5-frederic.danis@collabora.com> (raw)
In-Reply-To: <20260908170633.510244-1-frederic.danis@collabora.com>

This allows to store the expected location for a local endpoint.
---
 Makefile.tools               |   1 +
 client/btpclient/btpclient.h |   3 +
 client/btpclient/core.c      |  16 ++++++
 client/btpclient/pacs.c      | 107 +++++++++++++++++++++++++++++++++++
 client/btpclient/pacs.h      |  13 +++++
 src/shared/btp.h             |   9 +++
 6 files changed, 149 insertions(+)
 create mode 100644 client/btpclient/pacs.c
 create mode 100644 client/btpclient/pacs.h

diff --git a/Makefile.tools b/Makefile.tools
index 5c1130bff..0ca80a293 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -573,6 +573,7 @@ client_btpclient_btpclient_SOURCES = client/btpclient/btpclient.c \
 				client/btpclient/core.c client/btpclient/core.h \
 				client/btpclient/gap.c client/btpclient/gap.h \
 				client/btpclient/gatt.c client/btpclient/gatt.h \
+				client/btpclient/pacs.c client/btpclient/pacs.h \
 				client/btpclient/vendor.c client/btpclient/vendor.h
 client_btpclient_btpclient_LDADD = lib/libbluetooth-internal.la \
 				src/libshared-ell.la $(ell_ldadd)
diff --git a/client/btpclient/btpclient.h b/client/btpclient/btpclient.h
index 0d81405d3..2ba612ade 100644
--- a/client/btpclient/btpclient.h
+++ b/client/btpclient/btpclient.h
@@ -19,6 +19,9 @@ struct btp_adapter {
 	uint32_t default_settings;
 	struct l_queue *devices;
 
+	uint32_t sink_locations;
+	uint32_t source_locations;
+
 	uint8_t target_latency;
 };
 
diff --git a/client/btpclient/core.c b/client/btpclient/core.c
index 8ab3f3e34..bbbc7edfd 100644
--- a/client/btpclient/core.c
+++ b/client/btpclient/core.c
@@ -18,6 +18,7 @@
 #include "core.h"
 #include "gap.h"
 #include "gatt.h"
+#include "pacs.h"
 #include "vendor.h"
 
 static struct btp *btp;
@@ -67,6 +68,7 @@ static void btp_core_read_services(uint8_t index, const void *param,
 		BTP_CORE_SERVICE,
 		BTP_GAP_SERVICE,
 		BTP_GATT_SERVICE,
+		BTP_PACS_SERVICE,
 		BTP_ASCS_SERVICE,
 		BTP_BAP_SERVICE,
 		BTP_VENDOR_SERVICE,
@@ -130,6 +132,14 @@ static void btp_core_register(uint8_t index, const void *param,
 		if (!gatt_register_service(btp, dbus, client))
 			goto failed;
 
+		break;
+	case BTP_PACS_SERVICE:
+		if (pacs_is_service_registered())
+			goto failed;
+
+		if (!pacs_register_service(btp, dbus, client))
+			goto failed;
+
 		break;
 	case BTP_ASCS_SERVICE:
 		if (ascs_is_service_registered())
@@ -197,6 +207,12 @@ static void btp_core_unregister(uint8_t index, const void *param,
 
 		gatt_unregister_service(btp);
 		break;
+	case BTP_PACS_SERVICE:
+		if (!pacs_is_service_registered())
+			goto failed;
+
+		ascs_unregister_service(btp);
+		break;
 	case BTP_ASCS_SERVICE:
 		if (!ascs_is_service_registered())
 			goto failed;
diff --git a/client/btpclient/pacs.c b/client/btpclient/pacs.c
new file mode 100644
index 000000000..6277812a0
--- /dev/null
+++ b/client/btpclient/pacs.c
@@ -0,0 +1,107 @@
+// 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 <ell/ell.h>
+
+#include "bluetooth/bluetooth.h"
+#include "bluetooth/uuid.h"
+#include "src/shared/btp.h"
+#include "btpclient.h"
+#include "pacs.h"
+
+static struct btp *btp;
+static bool pacs_service_registered;
+
+static void btp_pacs_read_commands(uint8_t index, const void *param,
+					uint16_t length, void *user_data)
+{
+	const uint8_t supported_commands[] = {
+		BTP_OP_PACS_READ_SUPPORTED_COMMANDS,
+		BTP_OP_PACS_SET_LOCATION,
+	};
+	uint8_t *commands = NULL;
+	size_t commands_len = 0;
+	size_t i;
+
+	if (index != BTP_INDEX_NON_CONTROLLER) {
+		btp_send_error(btp, BTP_PACS_SERVICE, index,
+						BTP_ERROR_INVALID_INDEX);
+		return;
+	}
+
+	for (i = 0; i < L_ARRAY_SIZE(supported_commands); i++) {
+		if (!add_supported_command(&commands, &commands_len,
+						supported_commands[i]))
+			goto failed;
+	}
+
+	btp_send(btp, BTP_PACS_SERVICE, BTP_OP_PACS_READ_SUPPORTED_COMMANDS,
+			BTP_INDEX_NON_CONTROLLER, commands_len, commands);
+
+	l_free(commands);
+
+	return;
+
+failed:
+	l_free(commands);
+	btp_send_error(btp, BTP_PACS_SERVICE, index, BTP_ERROR_FAIL);
+}
+
+static void btp_pacs_set_location(uint8_t index, const void *param,
+					uint16_t length, void *user_data)
+{
+	struct btp_adapter *adapter = find_adapter_by_index(index);
+	const struct btp_pacs_set_location_cp *cp = param;
+
+	switch (cp->dir) {
+	case BTP_BAP_DIR_SINK:
+		adapter->sink_locations = cp->location;
+		break;
+	case BTP_BAP_DIR_SOURCE:
+		adapter->source_locations = cp->location;
+		break;
+	default:
+		btp_send_error(btp, BTP_PACS_SERVICE, index, BTP_ERROR_FAIL);
+		return;
+	}
+
+	btp_send(btp, BTP_PACS_SERVICE, BTP_OP_PACS_SET_LOCATION, index, 0,
+									NULL);
+}
+
+bool pacs_register_service(struct btp *btp_, struct l_dbus *dbus_,
+					struct l_dbus_client *client)
+{
+	btp = btp_;
+
+	btp_register(btp, BTP_PACS_SERVICE, BTP_OP_PACS_READ_SUPPORTED_COMMANDS,
+					btp_pacs_read_commands, NULL, NULL);
+
+	btp_register(btp, BTP_PACS_SERVICE, BTP_OP_PACS_SET_LOCATION,
+					btp_pacs_set_location, NULL, NULL);
+
+	pacs_service_registered = true;
+
+	return true;
+}
+
+void pacs_unregister_service(struct btp *btp)
+{
+	btp_unregister_service(btp, BTP_PACS_SERVICE);
+	pacs_service_registered = false;
+}
+
+bool pacs_is_service_registered(void)
+{
+	return pacs_service_registered;
+}
diff --git a/client/btpclient/pacs.h b/client/btpclient/pacs.h
new file mode 100644
index 000000000..a1579a8d6
--- /dev/null
+++ b/client/btpclient/pacs.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 pacs_register_service(struct btp *btp_, struct l_dbus *dbus_,
+					struct l_dbus_client *client);
+void pacs_unregister_service(struct btp *btp);
+bool pacs_is_service_registered(void);
diff --git a/src/shared/btp.h b/src/shared/btp.h
index 65a8c8b6a..8ad57f48f 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_PACS_SERVICE	12
 #define BTP_ASCS_SERVICE	13
 #define BTP_BAP_SERVICE		14
 #define BTP_VENDOR_SERVICE	255
@@ -427,6 +428,14 @@ struct btp_gatt_write_rp {
 	uint8_t att_response;
 } __packed;
 
+#define BTP_OP_PACS_READ_SUPPORTED_COMMANDS	0x01
+
+#define BTP_OP_PACS_SET_LOCATION		0x03
+struct btp_pacs_set_location_cp {
+	uint8_t dir;
+	uint32_t location;
+} __packed;
+
 #define BTP_OP_ASCS_READ_SUPPORTED_COMMANDS	0x01
 
 #define BTP_OP_ASCS_CONFIGURE_CODEC		0x02
-- 
2.43.0


  parent reply	other threads:[~2026-09-08 17:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08 17:06 [PATCH BlueZ v2 0/8] client/btpclient: Add BAP/ASCS/PACS support for auto-pts BAP tests Frédéric Danis
2026-09-08 17:06 ` [PATCH BlueZ v2 1/8] client/btpclient: Add BTP_EV_BAP_ASE_FOUND support Frédéric Danis
2026-09-08 17:59   ` client/btpclient: Add BAP/ASCS/PACS support for auto-pts BAP tests bluez.test.bot
2026-09-08 17:06 ` [PATCH BlueZ v2 2/8] client/btpclient: Get Codec capabilities on ASE reply Frédéric Danis
2026-09-08 17:06 ` [PATCH BlueZ v2 3/8] client/btpclient: Add ASCS BTP support Frédéric Danis
2026-09-08 17:06 ` Frédéric Danis [this message]
2026-09-08 17:06 ` [PATCH BlueZ v2 5/8] client/btpclient: Add BTP_OP_BAP_SEND support Frédéric Danis
2026-09-08 17:06 ` [PATCH BlueZ v2 6/8] client/btpclient: Add ASCS support for BAP/UCL/STR/* tests Frédéric Danis
2026-09-08 17:06 ` [PATCH BlueZ v2 7/8] client/btpclient: Defer CIG/CIS assignment based on Client/Server role Frédéric Danis
2026-09-08 17:06 ` [PATCH BlueZ v2 8/8] client/btpclient: Add stream auto acquire for BAP/USR/STR/* tests Frédéric Danis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260908170633.510244-5-frederic.danis@collabora.com \
    --to=frederic.danis@collabora.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.