linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: shwoseph <shwoseph@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: shwoseph@gmail.com
Subject: [PATCH BlueZ 1/1] [v2] ExcludeAdapter configuration setting for input profile
Date: Sat,  9 Jul 2022 14:35:24 -0400	[thread overview]
Message-ID: <20220709183524.13900-2-shwoseph@gmail.com> (raw)
In-Reply-To: <20220709183524.13900-1-shwoseph@gmail.com>

---
 profiles/input/device.c   | 22 ++++++++++++++++++++++
 profiles/input/device.h   |  4 ++++
 profiles/input/input.conf |  4 ++++
 profiles/input/manager.c  | 34 +++++++++++++++++++++++++++++++++-
 4 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/profiles/input/device.c b/profiles/input/device.c
index e2ac6ea60..0192e7977 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -82,6 +82,8 @@ struct input_device {
 static int idle_timeout = 0;
 static bool uhid_enabled = false;
 static bool classic_bonded_only = false;
+static char **exclude_adapters;
+static gsize num_exclude_adapters;
 
 void input_set_idle_timeout(int timeout)
 {
@@ -103,6 +105,26 @@ bool input_get_classic_bonded_only(void)
 	return classic_bonded_only;
 }
 
+char **input_get_exclude_adapters(void)
+{
+	return exclude_adapters;
+}
+
+void input_set_exclude_adapters(char **adapters)
+{
+	exclude_adapters = adapters;
+}
+
+gsize input_get_num_exclude_adapters(void)
+{
+	return num_exclude_adapters;
+}
+
+void input_set_num_exclude_adapters(gsize num)
+{
+	num_exclude_adapters = num;
+}
+
 static void input_device_enter_reconnect_mode(struct input_device *idev);
 static int connection_disconnect(struct input_device *idev, uint32_t flags);
 static int uhid_disconnect(struct input_device *idev);
diff --git a/profiles/input/device.h b/profiles/input/device.h
index cf0389417..04fe41e2d 100644
--- a/profiles/input/device.h
+++ b/profiles/input/device.h
@@ -19,6 +19,10 @@ void input_enable_userspace_hid(bool state);
 void input_set_classic_bonded_only(bool state);
 bool input_get_classic_bonded_only(void);
 void input_set_auto_sec(bool state);
+char **input_get_exclude_adapters(void);
+void input_set_exclude_adapters(char **address);
+gsize input_get_num_exclude_adapters(void);
+void input_set_num_exclude_adapters(gsize address);
 
 int input_device_register(struct btd_service *service);
 void input_device_unregister(struct btd_service *service);
diff --git a/profiles/input/input.conf b/profiles/input/input.conf
index 4c70bc561..c8ec5ee30 100644
--- a/profiles/input/input.conf
+++ b/profiles/input/input.conf
@@ -24,3 +24,7 @@
 # Enables upgrades of security automatically if required.
 # Defaults to true to maximize device compatibility.
 #LEAutoSecurity=true
+
+# Exclude adapters
+# Disables input plugin on adapters with specified bdaddrs
+#ExcludeAdapters=00:00:00:00:00:00,00:00:00:00:00:01
diff --git a/profiles/input/manager.c b/profiles/input/manager.c
index 92789a003..ca687b726 100644
--- a/profiles/input/manager.c
+++ b/profiles/input/manager.c
@@ -32,7 +32,23 @@
 
 static int hid_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
 {
-	return server_start(btd_adapter_get_address(adapter));
+	const bdaddr_t *address;
+	char addr[18];
+	char **exclude_adapters;
+	gsize num_exclude_adapters;
+	
+	address = btd_adapter_get_address(adapter);
+	ba2str(address, addr);
+	exclude_adapters = input_get_exclude_adapters();
+	num_exclude_adapters = input_get_num_exclude_adapters();
+
+	for (gsize i = 0; i < num_exclude_adapters; i++) {
+		if (strcmp(addr, exclude_adapters[i])) {
+			return 0;
+		}
+	}
+	
+	return server_start(address);
 }
 
 static void hid_server_remove(struct btd_profile *p,
@@ -83,6 +99,9 @@ static int input_init(void)
 	config = load_config_file(CONFIGDIR "/input.conf");
 	if (config) {
 		int idle_timeout;
+		char *exclude_adapters_str;
+		char **exclude_adapters;
+		gsize num_exclude_adapters;
 		gboolean uhid_enabled, classic_bonded_only, auto_sec;
 
 		idle_timeout = g_key_file_get_integer(config, "General",
@@ -121,6 +140,19 @@ static int input_init(void)
 		} else
 			g_clear_error(&err);
 
+		g_key_file_set_list_separator(config, ',');
+		
+		exclude_adapters_str = g_key_file_get_string(config, "General",
+				"ExcludeAdapters", &err);
+		exclude_adapters = g_key_file_get_string_list(config, "General",
+				"ExcludeAdapters", &num_exclude_adapters, &err);
+
+		if (!err) {
+			DBG("input.conf: ExcludeAdapters=%s", exclude_adapters_str);
+			input_set_exclude_adapters(exclude_adapters);
+			input_set_num_exclude_adapters(num_exclude_adapters);
+		} else
+			g_clear_error(&err);
 	}
 
 	btd_profile_register(&input_profile);
-- 
2.32.0


  reply	other threads:[~2022-07-09 18:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-09 18:35 [PATCH BlueZ 0/1] [v2] ExcludeAdapter configuration setting for input plugin shwoseph
2022-07-09 18:35 ` shwoseph [this message]
2022-07-09 19:30   ` bluez.test.bot
2022-07-12 18:17 ` [PATCH BlueZ 0/1] [v2] " Luiz Augusto von Dentz
     [not found]   ` <CAL2otiWQ-6GpUeB_jd2HV6zwou-Oh04nQjFQU2u_MBaB80F5qA@mail.gmail.com>
2022-07-12 20:04     ` Luiz Augusto von Dentz

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=20220709183524.13900-2-shwoseph@gmail.com \
    --to=shwoseph@gmail.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;
as well as URLs for NNTP newsgroup(s).