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

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