Diff between e253e59b13630bfcd9c4da1baec14b1372f2af1c and 5a80fa0d0408aa883417e083763d7fd57bd635c9

Changed Files

File Additions Deletions Status
src/adapter.c +21 -2 modified
src/agent.c +4 -0 modified
src/hcid.h +1 -0 modified
src/main.c +10 -0 modified
src/main.conf +5 -0 modified

Full Patch

diff --git a/src/adapter.c b/src/adapter.c
index 88b720a..db8a737 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3135,7 +3135,7 @@ void adapter_set_pairable(struct btd_adapter *adapter, bool enable)
 	if (current == enable)
 		return;
 
-	set_mode(adapter, MGMT_OP_SET_PAIRABLE, 0x01);
+	set_mode(adapter, MGMT_OP_SET_PAIRABLE, enable ? 0x01 : 0x00);
 }
 
 bool btd_adapter_get_powered(struct btd_adapter *adapter)
@@ -7024,7 +7024,26 @@ static void read_info_complete(uint8_t status, uint16_t length,
 			!(adapter->current_settings & MGMT_SETTING_LE))
 		set_mode(adapter, MGMT_OP_SET_LE, 0x01);
 
-	set_mode(adapter, MGMT_OP_SET_PAIRABLE, 0x01);
+	if (main_opts.always_pairable) {
+		if (!(adapter->current_settings & MGMT_SETTING_PAIRABLE))
+			set_mode(adapter, MGMT_OP_SET_PAIRABLE, 0x01);
+	} else {
+		struct agent *agent = agent_get(NULL);
+
+		if (adapter->current_settings & MGMT_SETTING_PAIRABLE) {
+			if (!agent)
+				set_mode(adapter, MGMT_OP_SET_PAIRABLE, 0x00);
+		} else {
+			if (agent)
+				set_mode(adapter, MGMT_OP_SET_PAIRABLE, 0x01);
+		}
+
+		if (agent) {
+			agent_unref(agent);
+			agent = NULL;
+		}
+	}
+
 	if (!kernel_conn_control)
 		set_mode(adapter, MGMT_OP_SET_CONNECTABLE, 0x01);
 
diff --git a/src/agent.c b/src/agent.c
index 8c1211c..70786c3 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -42,6 +42,7 @@
 
 #include "log.h"
 #include "error.h"
+#include "hcid.h"
 #include "dbus-common.h"
 #include "adapter.h"
 #include "device.h"
@@ -151,6 +152,9 @@ static void set_io_cap(struct btd_adapter *adapter, gpointer user_data)
 		io_cap = IO_CAPABILITY_NOINPUTNOOUTPUT;
 
 	adapter_set_io_capability(adapter, io_cap);
+
+	if (!main_opts.always_pairable)
+		adapter_set_pairable(adapter, agent ? true : false);
 }
 
 static bool add_default_agent(struct agent *agent)
diff --git a/src/hcid.h b/src/hcid.h
index 6040c71..5956124 100644
--- a/src/hcid.h
+++ b/src/hcid.h
@@ -29,6 +29,7 @@ struct main_opts {
 	uint16_t	autoto;
 	uint32_t	pairto;
 	uint32_t	discovto;
+	gboolean	always_pairable;
 	gboolean	reverse_sdp;
 	gboolean	name_resolv;
 	gboolean	debug_keys;
diff --git a/src/main.c b/src/main.c
index 15f98cf..5ec1ab3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -72,6 +72,7 @@ static const char * const supported_options[] = {
 	"Name",
 	"Class",
 	"DiscoverableTimeout",
+	"AlwaysPairable",
 	"PairableTimeout",
 	"AutoConnectTimeout",
 	"DeviceID",
@@ -200,6 +201,14 @@ static void parse_config(GKeyFile *config)
 
 	DBG("parsing main.conf");
 
+	boolean = g_key_file_get_boolean(config, "General",
+						"AlwaysPairable", &err);
+	if (err) {
+		DBG("%s", err->message);
+		g_clear_error(&err);
+	} else
+		main_opts.always_pairable = boolean;
+
 	val = g_key_file_get_integer(config, "General",
 						"DiscoverableTimeout", &err);
 	if (err) {
@@ -291,6 +300,7 @@ static void init_defaults(void)
 	memset(&main_opts, 0, sizeof(main_opts));
 	main_opts.name = g_strdup_printf("BlueZ %s", VERSION);
 	main_opts.class = 0x000000;
+	main_opts.always_pairable = FALSE;
 	main_opts.pairto = DEFAULT_PAIRABLE_TIMEOUT;
 	main_opts.discovto = DEFAULT_DISCOVERABLE_TIMEOUT;
 	main_opts.reverse_sdp = TRUE;
diff --git a/src/main.conf b/src/main.conf
index 3ebadde..1d62f24 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -10,6 +10,11 @@
 # considered. Defaults to '0x000000'.
 #Class = 0x000100
 
+# Whether adapters should always be set as pairable, regardless of
+# whether there is any agents registered. Setting to false (the default)
+# will make adapters only pairable once the first agent registers.
+#AlwaysPairable = false
+
 # How long to stay in discoverable mode before going back to non-discoverable
 # The value is in seconds. Default is 180, i.e. 3 minutes.
 # 0 = disable timer, i.e. stay discoverable forever