From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 2/3] client/btpclient: Move btp core service in its own file
Date: Mon, 16 Feb 2026 20:31:35 +0100 [thread overview]
Message-ID: <20260216193136.292051-2-frederic.danis@collabora.com> (raw)
In-Reply-To: <20260216193136.292051-1-frederic.danis@collabora.com>
Moving the btp services in their own files will simplify maintenance.
---
v1->v2: Fix make distcheck
Makefile.tools | 4 +-
client/btpclient/btpclient.c | 139 ++++----------------------------
client/btpclient/btpclient.h | 12 +++
client/btpclient/core.c | 150 +++++++++++++++++++++++++++++++++++
client/btpclient/core.h | 10 +++
5 files changed, 189 insertions(+), 126 deletions(-)
create mode 100644 client/btpclient/btpclient.h
create mode 100644 client/btpclient/core.c
create mode 100644 client/btpclient/core.h
diff --git a/Makefile.tools b/Makefile.tools
index edfb5282c..823a1e1dd 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -586,7 +586,9 @@ if BTPCLIENT
noinst_PROGRAMS += client/btpclient/btpclient client/btpclient/btpclientctl
client_btpclient_btpclient_SOURCES = client/btpclient/btpclient.c \
- src/shared/btp.c src/shared/btp.h
+ client/btpclient/btpclient.h \
+ src/shared/btp.c src/shared/btp.h \
+ client/btpclient/core.c client/btpclient/core.h
client_btpclient_btpclient_LDADD = lib/libbluetooth-internal.la \
src/libshared-ell.la $(ell_ldadd)
client/btpclient/btpclient.$(OBJEXT): src/libshared-ell.la ell/internal
diff --git a/client/btpclient/btpclient.c b/client/btpclient/btpclient.c
index b70e2b573..1e30f49eb 100644
--- a/client/btpclient/btpclient.c
+++ b/client/btpclient/btpclient.c
@@ -23,6 +23,8 @@
#include "bluetooth/bluetooth.h"
#include "src/shared/btp.h"
+#include "btpclient.h"
+#include "core.h"
#define AD_PATH "/org/bluez/advertising"
#define AG_PATH "/org/bluez/agent"
@@ -2769,138 +2771,25 @@ static void register_gap_service(void)
btp_gap_confirm_entry_rsp, NULL, NULL);
}
-static void btp_core_read_commands(uint8_t index, const void *param,
- uint16_t length, void *user_data)
-{
- uint8_t commands = 0;
-
- if (index != BTP_INDEX_NON_CONTROLLER) {
- btp_send_error(btp, BTP_CORE_SERVICE, index,
- BTP_ERROR_INVALID_INDEX);
- return;
- }
-
- commands |= (1 << BTP_OP_CORE_READ_SUPPORTED_COMMANDS);
- commands |= (1 << BTP_OP_CORE_READ_SUPPORTED_SERVICES);
- commands |= (1 << BTP_OP_CORE_REGISTER);
- commands |= (1 << BTP_OP_CORE_UNREGISTER);
-
- btp_send(btp, BTP_CORE_SERVICE, BTP_OP_CORE_READ_SUPPORTED_COMMANDS,
- BTP_INDEX_NON_CONTROLLER, sizeof(commands), &commands);
-}
-
-static void btp_core_read_services(uint8_t index, const void *param,
- uint16_t length, void *user_data)
-{
- uint8_t services = 0;
-
- if (index != BTP_INDEX_NON_CONTROLLER) {
- btp_send_error(btp, BTP_CORE_SERVICE, index,
- BTP_ERROR_INVALID_INDEX);
- return;
- }
-
- services |= (1 << BTP_CORE_SERVICE);
- services |= (1 << BTP_GAP_SERVICE);
-
- btp_send(btp, BTP_CORE_SERVICE, BTP_OP_CORE_READ_SUPPORTED_SERVICES,
- BTP_INDEX_NON_CONTROLLER, sizeof(services), &services);
-}
-
-static void btp_core_register(uint8_t index, const void *param,
- uint16_t length, void *user_data)
+bool gap_register_service(void)
{
- const struct btp_core_register_cp *cp = param;
-
- if (length < sizeof(*cp))
- goto failed;
-
- if (index != BTP_INDEX_NON_CONTROLLER) {
- btp_send_error(btp, BTP_CORE_SERVICE, index,
- BTP_ERROR_INVALID_INDEX);
- return;
- }
-
- switch (cp->service_id) {
- case BTP_GAP_SERVICE:
- if (gap_service_registered)
- goto failed;
-
- if (!register_default_agent(NULL,
- BTP_GAP_IOCAPA_NO_INPUT_NO_OUTPUT,
- register_default_agent_reply))
- goto failed;
-
- return;
- case BTP_GATT_SERVICE:
- case BTP_L2CAP_SERVICE:
- case BTP_MESH_NODE_SERVICE:
- case BTP_CORE_SERVICE:
- default:
- goto failed;
- }
-
- btp_send(btp, BTP_CORE_SERVICE, BTP_OP_CORE_REGISTER,
- BTP_INDEX_NON_CONTROLLER, 0, NULL);
- return;
+ if (!register_default_agent(NULL,
+ BTP_GAP_IOCAPA_NO_INPUT_NO_OUTPUT,
+ register_default_agent_reply))
+ return false;
-failed:
- btp_send_error(btp, BTP_CORE_SERVICE, index, BTP_ERROR_FAIL);
+ return true;
}
-static void btp_core_unregister(uint8_t index, const void *param,
- uint16_t length, void *user_data)
+void gap_unregister_service(void)
{
- const struct btp_core_unregister_cp *cp = param;
-
- if (length < sizeof(*cp))
- goto failed;
-
- if (index != BTP_INDEX_NON_CONTROLLER) {
- btp_send_error(btp, BTP_CORE_SERVICE, index,
- BTP_ERROR_INVALID_INDEX);
- return;
- }
-
- switch (cp->service_id) {
- case BTP_GAP_SERVICE:
- if (!gap_service_registered)
- goto failed;
-
- btp_unregister_service(btp, BTP_GAP_SERVICE);
- gap_service_registered = false;
- break;
- case BTP_GATT_SERVICE:
- case BTP_L2CAP_SERVICE:
- case BTP_MESH_NODE_SERVICE:
- case BTP_CORE_SERVICE:
- default:
- goto failed;
- }
-
- btp_send(btp, BTP_CORE_SERVICE, BTP_OP_CORE_UNREGISTER,
- BTP_INDEX_NON_CONTROLLER, 0, NULL);
- return;
-
-failed:
- btp_send_error(btp, BTP_CORE_SERVICE, index, BTP_ERROR_FAIL);
+ btp_unregister_service(btp, BTP_GAP_SERVICE);
+ gap_service_registered = false;
}
-static void register_core_service(void)
+bool gap_is_service_registered(void)
{
- btp_register(btp, BTP_CORE_SERVICE,
- BTP_OP_CORE_READ_SUPPORTED_COMMANDS,
- btp_core_read_commands, NULL, NULL);
-
- btp_register(btp, BTP_CORE_SERVICE,
- BTP_OP_CORE_READ_SUPPORTED_SERVICES,
- btp_core_read_services, NULL, NULL);
-
- btp_register(btp, BTP_CORE_SERVICE, BTP_OP_CORE_REGISTER,
- btp_core_register, NULL, NULL);
-
- btp_register(btp, BTP_CORE_SERVICE, BTP_OP_CORE_UNREGISTER,
- btp_core_unregister, NULL, NULL);
+ return gap_service_registered;
}
static void signal_handler(uint32_t signo, void *user_data)
@@ -3196,7 +3085,7 @@ static void client_ready(struct l_dbus_client *client, void *user_data)
btp_set_disconnect_handler(btp, btp_disconnect_handler, NULL, NULL);
- register_core_service();
+ core_register_service(btp);
btp_send(btp, BTP_CORE_SERVICE, BTP_EV_CORE_READY,
BTP_INDEX_NON_CONTROLLER, 0, NULL);
diff --git a/client/btpclient/btpclient.h b/client/btpclient/btpclient.h
new file mode 100644
index 000000000..467e48278
--- /dev/null
+++ b/client/btpclient/btpclient.h
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
+ *
+ */
+
+bool gap_register_service(void);
+void gap_unregister_service(void);
+bool gap_is_service_registered(void);
diff --git a/client/btpclient/core.c b/client/btpclient/core.c
new file mode 100644
index 000000000..1b4fa0390
--- /dev/null
+++ b/client/btpclient/core.c
@@ -0,0 +1,150 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
+ *
+ */
+
+#include <ell/ell.h>
+
+#include "bluetooth/bluetooth.h"
+#include "src/shared/btp.h"
+#include "btpclient.h"
+#include "core.h"
+
+static struct btp *btp;
+
+static void btp_core_read_commands(uint8_t index, const void *param,
+ uint16_t length, void *user_data)
+{
+ uint8_t commands = 0;
+
+ if (index != BTP_INDEX_NON_CONTROLLER) {
+ btp_send_error(btp, BTP_CORE_SERVICE, index,
+ BTP_ERROR_INVALID_INDEX);
+ return;
+ }
+
+ commands |= (1 << BTP_OP_CORE_READ_SUPPORTED_COMMANDS);
+ commands |= (1 << BTP_OP_CORE_READ_SUPPORTED_SERVICES);
+ commands |= (1 << BTP_OP_CORE_REGISTER);
+ commands |= (1 << BTP_OP_CORE_UNREGISTER);
+
+ btp_send(btp, BTP_CORE_SERVICE, BTP_OP_CORE_READ_SUPPORTED_COMMANDS,
+ BTP_INDEX_NON_CONTROLLER, sizeof(commands), &commands);
+}
+
+static void btp_core_read_services(uint8_t index, const void *param,
+ uint16_t length, void *user_data)
+{
+ uint8_t services = 0;
+
+ if (index != BTP_INDEX_NON_CONTROLLER) {
+ btp_send_error(btp, BTP_CORE_SERVICE, index,
+ BTP_ERROR_INVALID_INDEX);
+ return;
+ }
+
+ services |= (1 << BTP_CORE_SERVICE);
+ services |= (1 << BTP_GAP_SERVICE);
+
+ btp_send(btp, BTP_CORE_SERVICE, BTP_OP_CORE_READ_SUPPORTED_SERVICES,
+ BTP_INDEX_NON_CONTROLLER, sizeof(services), &services);
+}
+
+static void btp_core_register(uint8_t index, const void *param,
+ uint16_t length, void *user_data)
+{
+ const struct btp_core_register_cp *cp = param;
+
+ if (length < sizeof(*cp))
+ goto failed;
+
+ if (index != BTP_INDEX_NON_CONTROLLER) {
+ btp_send_error(btp, BTP_CORE_SERVICE, index,
+ BTP_ERROR_INVALID_INDEX);
+ return;
+ }
+
+ switch (cp->service_id) {
+ case BTP_GAP_SERVICE:
+ if (gap_is_service_registered())
+ goto failed;
+
+ if (!gap_register_service())
+ goto failed;
+
+ return;
+ case BTP_GATT_SERVICE:
+ case BTP_L2CAP_SERVICE:
+ case BTP_MESH_NODE_SERVICE:
+ case BTP_CORE_SERVICE:
+ default:
+ goto failed;
+ }
+
+ btp_send(btp, BTP_CORE_SERVICE, BTP_OP_CORE_REGISTER,
+ BTP_INDEX_NON_CONTROLLER, 0, NULL);
+ return;
+
+failed:
+ btp_send_error(btp, BTP_CORE_SERVICE, index, BTP_ERROR_FAIL);
+}
+
+static void btp_core_unregister(uint8_t index, const void *param,
+ uint16_t length, void *user_data)
+{
+ const struct btp_core_unregister_cp *cp = param;
+
+ if (length < sizeof(*cp))
+ goto failed;
+
+ if (index != BTP_INDEX_NON_CONTROLLER) {
+ btp_send_error(btp, BTP_CORE_SERVICE, index,
+ BTP_ERROR_INVALID_INDEX);
+ return;
+ }
+
+ switch (cp->service_id) {
+ case BTP_GAP_SERVICE:
+ if (!gap_is_service_registered())
+ goto failed;
+
+ gap_unregister_service();
+ break;
+ case BTP_GATT_SERVICE:
+ case BTP_L2CAP_SERVICE:
+ case BTP_MESH_NODE_SERVICE:
+ case BTP_CORE_SERVICE:
+ default:
+ goto failed;
+ }
+
+ btp_send(btp, BTP_CORE_SERVICE, BTP_OP_CORE_UNREGISTER,
+ BTP_INDEX_NON_CONTROLLER, 0, NULL);
+ return;
+
+failed:
+ btp_send_error(btp, BTP_CORE_SERVICE, index, BTP_ERROR_FAIL);
+}
+
+void core_register_service(struct btp *btp_)
+{
+ btp = btp_;
+
+ btp_register(btp, BTP_CORE_SERVICE,
+ BTP_OP_CORE_READ_SUPPORTED_COMMANDS,
+ btp_core_read_commands, NULL, NULL);
+
+ btp_register(btp, BTP_CORE_SERVICE,
+ BTP_OP_CORE_READ_SUPPORTED_SERVICES,
+ btp_core_read_services, NULL, NULL);
+
+ btp_register(btp, BTP_CORE_SERVICE, BTP_OP_CORE_REGISTER,
+ btp_core_register, NULL, NULL);
+
+ btp_register(btp, BTP_CORE_SERVICE, BTP_OP_CORE_UNREGISTER,
+ btp_core_unregister, NULL, NULL);
+}
diff --git a/client/btpclient/core.h b/client/btpclient/core.h
new file mode 100644
index 000000000..4c6d0437a
--- /dev/null
+++ b/client/btpclient/core.h
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
+ *
+ */
+
+void core_register_service(struct btp *btp);
--
2.43.0
next prev parent reply other threads:[~2026-02-16 19:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-16 19:31 [PATCH BlueZ v2 1/3] tools/btpclient: Move btpclient to client/btpclient directory Frédéric Danis
2026-02-16 19:31 ` Frédéric Danis [this message]
2026-02-16 19:31 ` [PATCH BlueZ v2 3/3] client/btpclient: Move btp GAP service in its own file Frédéric Danis
2026-02-16 20:28 ` [BlueZ,v2,1/3] tools/btpclient: Move btpclient to client/btpclient directory bluez.test.bot
2026-02-17 14:50 ` [PATCH BlueZ v2 1/3] " patchwork-bot+bluetooth
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=20260216193136.292051-2-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox