Blame SOURCES/0001-core-Add-AlwaysPairable-to-main.conf.patch

8866cd
From 370c254b22b98787b38732f47cf499f7a57289e2 Mon Sep 17 00:00:00 2001
8866cd
From: Gopal Tiwari <gtiwari@redhat.com>
8866cd
Date: Tue, 23 Jul 2019 18:04:27 +0530
8866cd
Subject: [PATCH BlueZ 1/2]     core: Add AlwaysPairable to main.conf
8866cd
8866cd
commit 1880b299086659844889cdaf687133aca5eaf102
8866cd
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
8866cd
Date:   Fri Jul 27 11:14:04 2018 +0300
8866cd
8866cd
    core: Add AlwaysPairable to main.conf
8866cd
8866cd
    This adds a new option called AlwaysPairable to main.conf, it can be
8866cd
    used to enable Adapter.Pairable even in case there is no Agent
8866cd
    available.
8866cd
8866cd
    Since that could be consider a security problem to allow pairing
8866cd
    without user's consent the option defaults to false.
8866cd
8866cd
Signed-off-by: Gopal Tiwari <gtiwari@redhat.com>
8866cd
---
8866cd
 src/adapter.c | 16 +++++++++++++++-
8866cd
 src/agent.h   |  7 +++++++
8866cd
 src/device.c  |  2 --
8866cd
 src/hcid.h    |  1 +
8866cd
 src/main.c    | 10 ++++++++++
8866cd
 src/main.conf |  5 +++++
8866cd
 6 files changed, 38 insertions(+), 3 deletions(-)
8866cd
8866cd
diff --git a/src/adapter.c b/src/adapter.c
8866cd
index 3dac7d649..d412bc58e 100644
8866cd
--- a/src/adapter.c
8866cd
+++ b/src/adapter.c
8866cd
@@ -7334,6 +7334,19 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)
8866cd
 {
8866cd
 	struct mgmt_cp_set_io_capability cp;
8866cd
 
8866cd
+	if (!main_opts.pairable) {
8866cd
+		if (io_cap == IO_CAPABILITY_INVALID) {
8866cd
+			if (adapter->current_settings & MGMT_SETTING_BONDABLE)
8866cd
+				set_mode(adapter, MGMT_OP_SET_BONDABLE, 0x00);
8866cd
+
8866cd
+			return 0;
8866cd
+		}
8866cd
+
8866cd
+		if (!(adapter->current_settings & MGMT_SETTING_BONDABLE))
8866cd
+			set_mode(adapter, MGMT_OP_SET_BONDABLE, 0x01);
8866cd
+	} else if (io_cap == IO_CAPABILITY_INVALID)
8866cd
+		io_cap = IO_CAPABILITY_NOINPUTNOOUTPUT;
8866cd
+
8866cd
 	memset(&cp, 0, sizeof(cp));
8866cd
 	cp.io_capability = io_cap;
8866cd
 
8866cd
@@ -8259,7 +8272,8 @@ static void read_info_complete(uint8_t status, uint16_t length,
8866cd
 
8866cd
 	set_name(adapter, btd_adapter_get_name(adapter));
8866cd
 
8866cd
-	if (!(adapter->current_settings & MGMT_SETTING_BONDABLE))
8866cd
+	if (main_opts.pairable &&
8866cd
+			!(adapter->current_settings & MGMT_SETTING_BONDABLE))
8866cd
 		set_mode(adapter, MGMT_OP_SET_BONDABLE, 0x01);
8866cd
 
8866cd
 	if (!kernel_conn_control)
8866cd
diff --git a/src/agent.h b/src/agent.h
8866cd
index 1e4692036..f14d14325 100644
8866cd
--- a/src/agent.h
8866cd
+++ b/src/agent.h
8866cd
@@ -22,6 +22,13 @@
8866cd
  *
8866cd
  */
8866cd
 
8866cd
+#define IO_CAPABILITY_DISPLAYONLY	0x00
8866cd
+#define IO_CAPABILITY_DISPLAYYESNO	0x01
8866cd
+#define IO_CAPABILITY_KEYBOARDONLY	0x02
8866cd
+#define IO_CAPABILITY_NOINPUTNOOUTPUT	0x03
8866cd
+#define IO_CAPABILITY_KEYBOARDDISPLAY	0x04
8866cd
+#define IO_CAPABILITY_INVALID		0xFF
8866cd
+
8866cd
 struct agent;
8866cd
 
8866cd
 typedef void (*agent_cb) (struct agent *agent, DBusError *err,
8866cd
diff --git a/src/device.c b/src/device.c
8866cd
index 8693eb826..43cd758d4 100644
8866cd
--- a/src/device.c
8866cd
+++ b/src/device.c
8866cd
@@ -75,8 +75,6 @@
8866cd
 #include "attrib-server.h"
8866cd
 #include "eir.h"
8866cd
 
8866cd
-#define IO_CAPABILITY_NOINPUTNOOUTPUT	0x03
8866cd
-
8866cd
 #define DISCONNECT_TIMER	2
8866cd
 #define DISCOVERY_TIMER		1
8866cd
 #define INVALID_FLAGS		0xff
8866cd
diff --git a/src/hcid.h b/src/hcid.h
8866cd
index 0b785ee9b..335ddeabf 100644
8866cd
--- a/src/hcid.h
8866cd
+++ b/src/hcid.h
8866cd
@@ -32,6 +32,7 @@ typedef enum {
8866cd
 struct main_opts {
8866cd
 	char		*name;
8866cd
 	uint32_t	class;
8866cd
+	gboolean	pairable;
8866cd
 	uint16_t	autoto;
8866cd
 	uint32_t	pairto;
8866cd
 	uint32_t	discovto;
8866cd
diff --git a/src/main.c b/src/main.c
8866cd
index bcc1e6fae..2d03ed459 100644
8866cd
--- a/src/main.c
8866cd
+++ b/src/main.c
8866cd
@@ -236,6 +236,16 @@ static void parse_config(GKeyFile *config)
8866cd
 		main_opts.discovto = val;
8866cd
 	}
8866cd
 
8866cd
+	boolean = g_key_file_get_boolean(config, "General",
8866cd
+						"AlwaysPairable", &err;;
8866cd
+	if (err) {
8866cd
+		DBG("%s", err->message);
8866cd
+		g_clear_error(&err;;
8866cd
+	} else {
8866cd
+		DBG("pairable=%s", boolean ? "true" : "false");
8866cd
+		main_opts.pairable = boolean;
8866cd
+	}
8866cd
+
8866cd
 	val = g_key_file_get_integer(config, "General",
8866cd
 						"PairableTimeout", &err;;
8866cd
 	if (err) {
8866cd
diff --git a/src/main.conf b/src/main.conf
8866cd
index a6492761b..c1ae35f11 100644
8866cd
--- a/src/main.conf
8866cd
+++ b/src/main.conf
8866cd
@@ -13,6 +13,11 @@
8866cd
 # 0 = disable timer, i.e. stay discoverable forever
8866cd
 #DiscoverableTimeout = 0
8866cd
 
8866cd
+# Always allow pairing even if there are no agent registered
8866cd
+# Possible values: true, false
8866cd
+# Default: false
8866cd
+#AlwaysPairable = false
8866cd
+
8866cd
 # How long to stay in pairable mode before going back to non-discoverable
8866cd
 # The value is in seconds. Default is 0.
8866cd
 # 0 = disable timer, i.e. stay pairable forever
8866cd
-- 
8866cd
2.17.2
8866cd