diff mbox series

[BlueZ,v1,2/3] main.conf: Add support for testing interfaces

Message ID 20240423224603.2124790-2-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ,v1,1/3] gdbus: Add testing flags | expand

Commit Message

Luiz Augusto von Dentz April 23, 2024, 10:46 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds support for D-Bus testing interfaces and testing profile
drivers.
---
 src/bluetoothd.rst.in | 9 +++++++--
 src/btd.h             | 1 +
 src/main.c            | 8 ++++++++
 src/main.conf         | 4 ++++
 src/profile.c         | 6 ++++++
 src/profile.h         | 5 +++++
 6 files changed, 31 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/bluetoothd.rst.in b/src/bluetoothd.rst.in
index 7a0fa1b24469..0b998f621595 100644
--- a/src/bluetoothd.rst.in
+++ b/src/bluetoothd.rst.in
@@ -64,8 +64,13 @@  OPTIONS
 
 -C, --compat        Provide deprecated command line interfaces.
 
--E, --experimental  Enable experimental interfaces. Those interfaces are not
-                    guaranteed to be compatible or present in future releases.
+-E, --experimental  Enable D-Bus experimental interfaces.
+    These interfaces are not guaranteed to be compatible or present in future
+    releases.
+
+-T, --testing  Enable D-Bus testing interfaces.
+    These interfaces are only meant for test validation of the internals of
+    bluetoothd and shall not never be used by anything other than that.
 
 -K, --kernel=<uuid1>,<uuid2>,...
     Enable Kernel experimental features. Kernel experimental features are
diff --git a/src/btd.h b/src/btd.h
index 8c80059ac1d8..383bd7c19600 100644
--- a/src/btd.h
+++ b/src/btd.h
@@ -128,6 +128,7 @@  struct btd_opts {
 	bool		fast_conn;
 	bool		refresh_discovery;
 	bool		experimental;
+	bool		testing;
 	struct queue	*kernel;
 
 	uint16_t	did_source;
diff --git a/src/main.c b/src/main.c
index 78831ad02520..23af6781d931 100644
--- a/src/main.c
+++ b/src/main.c
@@ -87,6 +87,7 @@  static const char *supported_options[] = {
 	"TemporaryTimeout",
 	"RefreshDiscovery",
 	"Experimental",
+	"Testing",
 	"KernelExperimental",
 	"RemoteNameRequestRetryDelay",
 	NULL
@@ -1034,6 +1035,8 @@  static void parse_general(GKeyFile *config)
 	parse_secure_conns(config);
 	parse_config_bool(config, "General", "Experimental",
 						&btd_opts.experimental);
+	parse_config_bool(config, "General", "Testing",
+						&btd_opts.testing);
 	parse_kernel_exp(config);
 	parse_config_u32(config, "General", "RemoteNameRequestRetryDelay",
 					&btd_opts.name_request_retry_delay,
@@ -1344,6 +1347,8 @@  static GOptionEntry options[] = {
 				"Provide deprecated command line interfaces" },
 	{ "experimental", 'E', 0, G_OPTION_ARG_NONE, &btd_opts.experimental,
 				"Enable experimental D-Bus interfaces" },
+	{ "testing", 'T', 0, G_OPTION_ARG_NONE, &btd_opts.testing,
+				"Enable testing D-Bus interfaces" },
 	{ "kernel", 'K', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK,
 				parse_kernel_experimental,
 				"Enable kernel experimental features" },
@@ -1410,6 +1415,9 @@  int main(int argc, char *argv[])
 	if (btd_opts.experimental)
 		gdbus_flags = G_DBUS_FLAG_ENABLE_EXPERIMENTAL;
 
+	if (btd_opts.testing)
+		gdbus_flags |= G_DBUS_FLAG_ENABLE_TESTING;
+
 	g_dbus_set_flags(gdbus_flags);
 
 	if (adapter_init() < 0) {
diff --git a/src/main.conf b/src/main.conf
index 49864b5c35f5..bea94640e627 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -126,6 +126,10 @@ 
 # Possible values: true or false
 #Experimental = false
 
+# Enables D-Bus testing interfaces
+# Possible values: true or false
+#Testing = false
+
 # Enables kernel experimental features, alternatively a list of UUIDs
 # can be given.
 # Possible values: true,false,<UUID List>
diff --git a/src/profile.c b/src/profile.c
index ea188f36b6dd..c62224af9dd8 100644
--- a/src/profile.c
+++ b/src/profile.c
@@ -781,6 +781,12 @@  int btd_profile_register(struct btd_profile *profile)
 		return -ENOTSUP;
 	}
 
+	if (profile->testing && !(g_dbus_get_flags() &
+					G_DBUS_FLAG_ENABLE_TESTING)) {
+		DBG("D-Bus testing not enabled");
+		return -ENOTSUP;
+	}
+
 	profiles = g_slist_append(profiles, profile);
 	return 0;
 }
diff --git a/src/profile.h b/src/profile.h
index 6871f2f0d7d8..424ce55ad657 100644
--- a/src/profile.h
+++ b/src/profile.h
@@ -33,6 +33,11 @@  struct btd_profile {
 	 */
 	bool experimental;
 
+	/* Indicates the profile for testing only and shall only be registered
+	 * when testing has been enabled (see: main.conf:Testing).
+	 */
+	bool testing;
+
 	int (*device_probe) (struct btd_service *service);
 	void (*device_remove) (struct btd_service *service);