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

eb98a2
From 4aa826664dd5d6e784162c2393149ecb01550fb1 Mon Sep 17 00:00:00 2001
eb98a2
From: Gopal Tiwari <gtiwari@redhat.com>
eb98a2
Date: Wed, 18 Dec 2019 19:31:49 +0530
eb98a2
Subject: [PATCH BlueZ 1/2] core: Add AlwaysPairable to main.conf
eb98a2
eb98a2
commit 1880b299086659844889cdaf687133aca5eaf102
eb98a2
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
eb98a2
Date:   Fri Jul 27 11:14:04 2018 +0300
eb98a2
eb98a2
    core: Add AlwaysPairable to main.conf
eb98a2
eb98a2
    This adds a new option called AlwaysPairable to main.conf, it can be
eb98a2
    used to enable Adapter.Pairable even in case there is no Agent
eb98a2
    available.
eb98a2
eb98a2
    Since that could be consider a security problem to allow pairing
eb98a2
    without user's consent the option defaults to false.
eb98a2
---
eb98a2
 src/adapter.c | 16 +++++++++++++++-
eb98a2
 src/agent.h   |  7 +++++++
eb98a2
 src/device.c  |  2 --
eb98a2
 src/hcid.h    |  1 +
eb98a2
 src/main.c    | 11 +++++++++++
eb98a2
 src/main.conf |  5 +++++
eb98a2
 6 files changed, 39 insertions(+), 3 deletions(-)
eb98a2
eb98a2
diff --git a/src/adapter.c b/src/adapter.c
eb98a2
index af340fd6e..720621f47 100644
eb98a2
--- a/src/adapter.c
eb98a2
+++ b/src/adapter.c
eb98a2
@@ -7754,6 +7754,19 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)
eb98a2
 {
eb98a2
 	struct mgmt_cp_set_io_capability cp;
eb98a2
 
eb98a2
+	if (!main_opts.pairable) {
eb98a2
+		if (io_cap == IO_CAPABILITY_INVALID) {
eb98a2
+			if (adapter->current_settings & MGMT_SETTING_BONDABLE)
eb98a2
+				set_mode(adapter, MGMT_OP_SET_BONDABLE, 0x00);
eb98a2
+
eb98a2
+			return 0;
eb98a2
+		}
eb98a2
+
eb98a2
+		if (!(adapter->current_settings & MGMT_SETTING_BONDABLE))
eb98a2
+			set_mode(adapter, MGMT_OP_SET_BONDABLE, 0x01);
eb98a2
+	} else if (io_cap == IO_CAPABILITY_INVALID)
eb98a2
+		io_cap = IO_CAPABILITY_NOINPUTNOOUTPUT;
eb98a2
+
eb98a2
 	memset(&cp, 0, sizeof(cp));
eb98a2
 	cp.io_capability = io_cap;
eb98a2
 
eb98a2
@@ -8682,7 +8695,8 @@ static void read_info_complete(uint8_t status, uint16_t length,
eb98a2
 
eb98a2
 	set_name(adapter, btd_adapter_get_name(adapter));
eb98a2
 
eb98a2
-	if (!(adapter->current_settings & MGMT_SETTING_BONDABLE))
eb98a2
+	if (main_opts.pairable &&
eb98a2
+			!(adapter->current_settings & MGMT_SETTING_BONDABLE))
eb98a2
 		set_mode(adapter, MGMT_OP_SET_BONDABLE, 0x01);
eb98a2
 
eb98a2
 	if (!kernel_conn_control)
eb98a2
diff --git a/src/agent.h b/src/agent.h
eb98a2
index 1e4692036..f14d14325 100644
eb98a2
--- a/src/agent.h
eb98a2
+++ b/src/agent.h
eb98a2
@@ -22,6 +22,13 @@
eb98a2
  *
eb98a2
  */
eb98a2
 
eb98a2
+#define IO_CAPABILITY_DISPLAYONLY	0x00
eb98a2
+#define IO_CAPABILITY_DISPLAYYESNO	0x01
eb98a2
+#define IO_CAPABILITY_KEYBOARDONLY	0x02
eb98a2
+#define IO_CAPABILITY_NOINPUTNOOUTPUT	0x03
eb98a2
+#define IO_CAPABILITY_KEYBOARDDISPLAY	0x04
eb98a2
+#define IO_CAPABILITY_INVALID		0xFF
eb98a2
+
eb98a2
 struct agent;
eb98a2
 
eb98a2
 typedef void (*agent_cb) (struct agent *agent, DBusError *err,
eb98a2
diff --git a/src/device.c b/src/device.c
eb98a2
index 4f1af7012..0d7907a69 100644
eb98a2
--- a/src/device.c
eb98a2
+++ b/src/device.c
eb98a2
@@ -75,8 +75,6 @@
eb98a2
 #include "attrib-server.h"
eb98a2
 #include "eir.h"
eb98a2
 
eb98a2
-#define IO_CAPABILITY_NOINPUTNOOUTPUT	0x03
eb98a2
-
eb98a2
 #define DISCONNECT_TIMER	2
eb98a2
 #define DISCOVERY_TIMER		1
eb98a2
 #define INVALID_FLAGS		0xff
eb98a2
diff --git a/src/hcid.h b/src/hcid.h
eb98a2
index 2c2b89d9c..ba250578a 100644
eb98a2
--- a/src/hcid.h
eb98a2
+++ b/src/hcid.h
eb98a2
@@ -38,6 +38,7 @@ typedef enum {
eb98a2
 struct main_opts {
eb98a2
 	char		*name;
eb98a2
 	uint32_t	class;
eb98a2
+	gboolean	pairable;
eb98a2
 	uint32_t	pairto;
eb98a2
 	uint32_t	discovto;
eb98a2
 	uint8_t		privacy;
eb98a2
diff --git a/src/main.c b/src/main.c
eb98a2
index 7e6af42cd..156406343 100644
eb98a2
--- a/src/main.c
eb98a2
+++ b/src/main.c
eb98a2
@@ -81,6 +81,7 @@ static const char *supported_options[] = {
eb98a2
 	"Name",
eb98a2
 	"Class",
eb98a2
 	"DiscoverableTimeout",
eb98a2
+	"AlwaysPairable"
eb98a2
 	"PairableTimeout",
eb98a2
 	"DeviceID",
eb98a2
 	"ReverseServiceDiscovery",
eb98a2
@@ -287,6 +288,16 @@ static void parse_config(GKeyFile *config)
eb98a2
 		main_opts.discovto = val;
eb98a2
 	}
eb98a2
 
eb98a2
+	boolean = g_key_file_get_boolean(config, "General",
eb98a2
+						"AlwaysPairable", &err;;
eb98a2
+	if (err) {
eb98a2
+		DBG("%s", err->message);
eb98a2
+		g_clear_error(&err;;
eb98a2
+	} else {
eb98a2
+		DBG("pairable=%s", boolean ? "true" : "false");
eb98a2
+		main_opts.pairable = boolean;
eb98a2
+	}
eb98a2
+
eb98a2
 	val = g_key_file_get_integer(config, "General",
eb98a2
 						"PairableTimeout", &err;;
eb98a2
 	if (err) {
eb98a2
diff --git a/src/main.conf b/src/main.conf
eb98a2
index cbae32ec5..0d480d183 100644
eb98a2
--- a/src/main.conf
eb98a2
+++ b/src/main.conf
eb98a2
@@ -13,6 +13,11 @@
eb98a2
 # 0 = disable timer, i.e. stay discoverable forever
eb98a2
 #DiscoverableTimeout = 0
eb98a2
 
eb98a2
+# Always allow pairing even if there are no agent registered
eb98a2
+# Possible values: true, false
eb98a2
+# Default: false
eb98a2
+#AlwaysPairable = false
eb98a2
+
eb98a2
 # How long to stay in pairable mode before going back to non-discoverable
eb98a2
 # The value is in seconds. Default is 0.
eb98a2
 # 0 = disable timer, i.e. stay pairable forever
eb98a2
-- 
eb98a2
2.17.2
eb98a2