Diff between 45969a7a7335eaa47c52b76b9e32c28d680dc031 and 1880b299086659844889cdaf687133aca5eaf102

Changed Files

File Additions Deletions Status
src/adapter.c +15 -1 modified
src/agent.h +7 -0 modified
src/device.c +0 -2 modified
src/hcid.h +1 -0 modified
src/main.c +11 -0 modified
src/main.conf +5 -0 modified

Full Patch

diff --git a/src/adapter.c b/src/adapter.c
index f92c897..f730c16 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -7792,6 +7792,19 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)
 {
 	struct mgmt_cp_set_io_capability cp;
 
+	if (!main_opts.pairable) {
+		if (io_cap == IO_CAPABILITY_INVALID) {
+			if (adapter->current_settings & MGMT_SETTING_BONDABLE)
+				set_mode(adapter, MGMT_OP_SET_BONDABLE, 0x00);
+
+			return 0;
+		}
+
+		if (!(adapter->current_settings & MGMT_SETTING_BONDABLE))
+			set_mode(adapter, MGMT_OP_SET_BONDABLE, 0x01);
+	} else if (io_cap == IO_CAPABILITY_INVALID)
+		io_cap = IO_CAPABILITY_NOINPUTNOOUTPUT;
+
 	memset(&cp, 0, sizeof(cp));
 	cp.io_capability = io_cap;
 
@@ -8720,7 +8733,8 @@ static void read_info_complete(uint8_t status, uint16_t length,
 
 	set_name(adapter, btd_adapter_get_name(adapter));
 
-	if (!(adapter->current_settings & MGMT_SETTING_BONDABLE))
+	if (main_opts.pairable &&
+			!(adapter->current_settings & MGMT_SETTING_BONDABLE))
 		set_mode(adapter, MGMT_OP_SET_BONDABLE, 0x01);
 
 	if (!kernel_conn_control)
diff --git a/src/agent.h b/src/agent.h
index 1e46920..f14d143 100644
--- a/src/agent.h
+++ b/src/agent.h
@@ -22,6 +22,13 @@
  *
  */
 
+#define IO_CAPABILITY_DISPLAYONLY	0x00
+#define IO_CAPABILITY_DISPLAYYESNO	0x01
+#define IO_CAPABILITY_KEYBOARDONLY	0x02
+#define IO_CAPABILITY_NOINPUTNOOUTPUT	0x03
+#define IO_CAPABILITY_KEYBOARDDISPLAY	0x04
+#define IO_CAPABILITY_INVALID		0xFF
+
 struct agent;
 
 typedef void (*agent_cb) (struct agent *agent, DBusError *err,
diff --git a/src/device.c b/src/device.c
index 77f94ff..ef5b8f8 100644
--- a/src/device.c
+++ b/src/device.c
@@ -75,8 +75,6 @@
 #include "attrib-server.h"
 #include "eir.h"
 
-#define IO_CAPABILITY_NOINPUTNOOUTPUT	0x03
-
 #define DISCONNECT_TIMER	2
 #define DISCOVERY_TIMER		1
 #define INVALID_FLAGS		0xff
diff --git a/src/hcid.h b/src/hcid.h
index 704f0ba..1eb3c5a 100644
--- a/src/hcid.h
+++ b/src/hcid.h
@@ -38,6 +38,7 @@ typedef enum {
 struct main_opts {
 	char		*name;
 	uint32_t	class;
+	gboolean	pairable;
 	uint32_t	pairto;
 	uint32_t	discovto;
 	uint8_t		privacy;
diff --git a/src/main.c b/src/main.c
index 4e2c424..4716f53 100644
--- a/src/main.c
+++ b/src/main.c
@@ -82,6 +82,7 @@ static const char *supported_options[] = {
 	"Name",
 	"Class",
 	"DiscoverableTimeout",
+	"AlwaysPairable"
 	"PairableTimeout",
 	"DeviceID",
 	"ReverseServiceDiscovery",
@@ -289,6 +290,16 @@ static void parse_config(GKeyFile *config)
 		main_opts.discovto = val;
 	}
 
+	boolean = g_key_file_get_boolean(config, "General",
+						"AlwaysPairable", &err);
+	if (err) {
+		DBG("%s", err->message);
+		g_clear_error(&err);
+	} else {
+		DBG("pairable=%s", boolean ? "true" : "false");
+		main_opts.pairable = boolean;
+	}
+
 	val = g_key_file_get_integer(config, "General",
 						"PairableTimeout", &err);
 	if (err) {
diff --git a/src/main.conf b/src/main.conf
index 224334c..b2f843c 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -13,6 +13,11 @@
 # 0 = disable timer, i.e. stay discoverable forever
 #DiscoverableTimeout = 0
 
+# Always allow pairing even if there are no agent registered
+# Possible values: true, false
+# Default: false
+#AlwaysPairable = false
+
 # How long to stay in pairable mode before going back to non-discoverable
 # The value is in seconds. Default is 0.
 # 0 = disable timer, i.e. stay pairable forever