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

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