Diff between 86f4b55232de3c8c1be87f22ad3a404316afb110 and f8a0c50bc6632455d1533d322935e9ebff6f4432

Changed Files

File Additions Deletions Status
plugins/policy.c +29 -5 modified
src/main.conf +9 -0 modified

Full Patch

diff --git a/plugins/policy.c b/plugins/policy.c
index 7d65797..b72467e 100644
--- a/plugins/policy.c
+++ b/plugins/policy.c
@@ -40,6 +40,7 @@
 #include "src/device.h"
 #include "src/service.h"
 #include "src/profile.h"
+#include "src/hcid.h"
 
 #define CONTROL_CONNECT_TIMEOUT 2
 #define SOURCE_RETRY_TIMEOUT 2
@@ -535,6 +536,13 @@ static void service_cb(struct btd_service *service,
 		target_cb(service, old_state, new_state);
 
 	/*
+	 * Return if the reconnection feature is not enabled (all
+	 * subsequent code in this function is about that).
+	 */
+	if (!reconnect_uuids)
+		return;
+
+	/*
 	 * We're only interested in reconnecting profiles which have set
 	 * auto_connect to true.
 	 */
@@ -660,14 +668,30 @@ static void conn_fail_cb(struct btd_device *dev, uint8_t status)
 
 static int policy_init(void)
 {
-	service_id = btd_service_add_state_cb(service_cb, NULL);
+	GError *gerr = NULL;
+	GKeyFile *conf;
 
-	/* TODO: Add overriding default from config file */
-	reconnect_uuids = g_strdupv((char **) default_reconnect);
+	service_id = btd_service_add_state_cb(service_cb, NULL);
 
-	btd_add_disconnect_cb(disconnect_cb);
+	conf = btd_get_main_conf();
+	if (!conf) {
+		reconnect_uuids = g_strdupv((char **) default_reconnect);
+		goto add_cb;
+	}
 
-	btd_add_conn_fail_cb(conn_fail_cb);
+	reconnect_uuids = g_key_file_get_string_list(conf, "Policy",
+							"ReconnectUUIDs",
+							NULL, &gerr);
+	if (gerr) {
+		g_error_free(gerr);
+		reconnect_uuids = g_strdupv((char **) default_reconnect);
+		goto add_cb;
+	}
+add_cb:
+	if (reconnect_uuids) {
+		btd_add_disconnect_cb(disconnect_cb);
+		btd_add_conn_fail_cb(conn_fail_cb);
+	}
 
 	return 0;
 }
diff --git a/src/main.conf b/src/main.conf
index a94274a..3ebadde 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -46,3 +46,12 @@
 # makes debug link keys valid only for the duration of the connection
 # that they were created for.
 #DebugKeys = false
+
+#[Policy]
+#
+# The ReconnectUUIDs defines the set of remote services that should try
+# to be reconnected to in case of a link loss (link supervision
+# timeout). The policy plugin should contain a sane set of values by
+# default, but this list can be overridden here. By setting the list to
+# empty the reconnection feature gets disabled.
+#ReconnectUUIDs=