* [PATCH] policy: Add AutoEnable config option
@ 2015-09-22 21:42 Szymon Janc
2015-09-28 18:32 ` Szymon Janc
0 siblings, 1 reply; 2+ messages in thread
From: Szymon Janc @ 2015-09-22 21:42 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This option is used to configure policy for auto enabling adapters when
found. This includes adapters found on start as well as adapters that
are plugged in later on.
This allows distributions to automatically enable adapters in race free
manner even if no agent is provided eg. in login screen.
---
plugins/policy.c | 29 +++++++++++++++++++++++++++--
src/main.conf | 5 +++++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/plugins/policy.c b/plugins/policy.c
index 6bb8268..218a3ed 100644
--- a/plugins/policy.c
+++ b/plugins/policy.c
@@ -80,6 +80,8 @@ static GSList *reconnects = NULL;
static unsigned int service_id = 0;
static GSList *devices = NULL;
+static bool auto_enable = false;
+
struct policy_data {
struct btd_device *dev;
@@ -743,6 +745,20 @@ static void conn_fail_cb(struct btd_device *dev, uint8_t status)
reconnect_set_timer(reconnect);
}
+static int policy_adapter_probe(struct btd_adapter *adapter)
+{
+ DBG("");
+
+ btd_adapter_restore_powered(adapter);
+
+ return 0;
+}
+
+static struct btd_adapter_driver policy_driver = {
+ .name = "policy",
+ .probe = policy_adapter_probe,
+};
+
static int policy_init(void)
{
GError *gerr = NULL;
@@ -758,7 +774,7 @@ static int policy_init(void)
sizeof(*reconnect_intervals);
reconnect_intervals = g_memdup(default_intervals,
reconnect_intervals_len);
- goto add_cb;
+ goto done;
}
reconnect_uuids = g_key_file_get_string_list(conf, "Policy",
@@ -788,12 +804,18 @@ static int policy_init(void)
reconnect_intervals_len);
}
-add_cb:
+ auto_enable = g_key_file_get_boolean(conf, "Policy", "AutoEnable",
+ NULL);
+
+done:
if (reconnect_uuids && reconnect_uuids[0] && reconnect_attempts) {
btd_add_disconnect_cb(disconnect_cb);
btd_add_conn_fail_cb(conn_fail_cb);
}
+ if (auto_enable)
+ btd_register_adapter_driver(&policy_driver);
+
return 0;
}
@@ -812,6 +834,9 @@ static void policy_exit(void)
g_slist_free_full(devices, policy_remove);
btd_service_remove_state_cb(service_id);
+
+ if (auto_enable)
+ btd_unregister_adapter_driver(&policy_driver);
}
BLUETOOTH_PLUGIN_DEFINE(policy, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
diff --git a/src/main.conf b/src/main.conf
index 6780d9a..372fd8c 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -82,3 +82,8 @@
# If the number of attempts defined in ReconnectAttempts is bigger than the
# set of intervals the last interval is repeated until the last attempt.
#ReconnectIntervals=1, 2, 4, 8, 16, 32, 64
+
+# AutoEnable defines option to enable all controllers when they are found.
+# This includes adapters present on start as well as adapters that are plugged
+# in later on. Defaults to 'false'.
+#AutoEnable=false
--
2.5.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] policy: Add AutoEnable config option
2015-09-22 21:42 [PATCH] policy: Add AutoEnable config option Szymon Janc
@ 2015-09-28 18:32 ` Szymon Janc
0 siblings, 0 replies; 2+ messages in thread
From: Szymon Janc @ 2015-09-28 18:32 UTC (permalink / raw)
To: linux-bluetooth
On Tuesday 22 September 2015 23:42:49 Szymon Janc wrote:
> This option is used to configure policy for auto enabling adapters when
> found. This includes adapters found on start as well as adapters that
> are plugged in later on.
>
> This allows distributions to automatically enable adapters in race free
> manner even if no agent is provided eg. in login screen.
> ---
> plugins/policy.c | 29 +++++++++++++++++++++++++++--
> src/main.conf | 5 +++++
> 2 files changed, 32 insertions(+), 2 deletions(-)
>
> diff --git a/plugins/policy.c b/plugins/policy.c
> index 6bb8268..218a3ed 100644
> --- a/plugins/policy.c
> +++ b/plugins/policy.c
> @@ -80,6 +80,8 @@ static GSList *reconnects = NULL;
> static unsigned int service_id = 0;
> static GSList *devices = NULL;
>
> +static bool auto_enable = false;
> +
> struct policy_data {
> struct btd_device *dev;
>
> @@ -743,6 +745,20 @@ static void conn_fail_cb(struct btd_device *dev,
> uint8_t status) reconnect_set_timer(reconnect);
> }
>
> +static int policy_adapter_probe(struct btd_adapter *adapter)
> +{
> + DBG("");
> +
> + btd_adapter_restore_powered(adapter);
> +
> + return 0;
> +}
> +
> +static struct btd_adapter_driver policy_driver = {
> + .name = "policy",
> + .probe = policy_adapter_probe,
> +};
> +
> static int policy_init(void)
> {
> GError *gerr = NULL;
> @@ -758,7 +774,7 @@ static int policy_init(void)
> sizeof(*reconnect_intervals);
> reconnect_intervals = g_memdup(default_intervals,
> reconnect_intervals_len);
> - goto add_cb;
> + goto done;
> }
>
> reconnect_uuids = g_key_file_get_string_list(conf, "Policy",
> @@ -788,12 +804,18 @@ static int policy_init(void)
> reconnect_intervals_len);
> }
>
> -add_cb:
> + auto_enable = g_key_file_get_boolean(conf, "Policy", "AutoEnable",
> + NULL);
> +
> +done:
> if (reconnect_uuids && reconnect_uuids[0] && reconnect_attempts) {
> btd_add_disconnect_cb(disconnect_cb);
> btd_add_conn_fail_cb(conn_fail_cb);
> }
>
> + if (auto_enable)
> + btd_register_adapter_driver(&policy_driver);
> +
> return 0;
> }
>
> @@ -812,6 +834,9 @@ static void policy_exit(void)
> g_slist_free_full(devices, policy_remove);
>
> btd_service_remove_state_cb(service_id);
> +
> + if (auto_enable)
> + btd_unregister_adapter_driver(&policy_driver);
> }
>
> BLUETOOTH_PLUGIN_DEFINE(policy, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
> diff --git a/src/main.conf b/src/main.conf
> index 6780d9a..372fd8c 100644
> --- a/src/main.conf
> +++ b/src/main.conf
> @@ -82,3 +82,8 @@
> # If the number of attempts defined in ReconnectAttempts is bigger than the
> # set of intervals the last interval is repeated until the last attempt.
> #ReconnectIntervals=1, 2, 4, 8, 16, 32, 64
> +
> +# AutoEnable defines option to enable all controllers when they are found.
> +# This includes adapters present on start as well as adapters that are
> plugged +# in later on. Defaults to 'false'.
> +#AutoEnable=false
Applied.
--
pozdrawiam
Szymon Janc
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-09-28 18:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-22 21:42 [PATCH] policy: Add AutoEnable config option Szymon Janc
2015-09-28 18:32 ` Szymon Janc
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).