From: Szymon Janc <szymon.janc@codecoup.pl>
To: linux-bluetooth@vger.kernel.org
Cc: Szymon Janc <szymon.janc@codecoup.pl>
Subject: [RFC 4/5] plugins/policy: Disable policies on authentication failure
Date: Thu, 4 Aug 2016 15:28:38 +0200 [thread overview]
Message-ID: <1470317319-3985-5-git-send-email-szymon.janc@codecoup.pl> (raw)
In-Reply-To: <1470317319-3985-1-git-send-email-szymon.janc@codecoup.pl>
If remote device was disconnected due to authentication failure (lost
bond) there is no point in trying to reconnect.
---
plugins/policy.c | 58 +++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 43 insertions(+), 15 deletions(-)
diff --git a/plugins/policy.c b/plugins/policy.c
index 0330456..933a968 100644
--- a/plugins/policy.c
+++ b/plugins/policy.c
@@ -93,6 +93,8 @@ struct policy_data {
uint8_t ct_retries;
guint tg_timer;
uint8_t tg_retries;
+
+ bool auth_failure;
};
static struct reconnect_data *reconnect_find(struct btd_device *dev)
@@ -172,22 +174,34 @@ static struct policy_data *find_data(struct btd_device *dev)
return NULL;
}
-static void policy_remove(void *user_data)
+static void policy_reset(struct policy_data *data)
{
- struct policy_data *data = user_data;
-
- if (data->source_timer > 0)
+ if (data->source_timer > 0) {
g_source_remove(data->source_timer);
+ data->source_timer = 0;
+ }
- if (data->sink_timer > 0)
+ if (data->sink_timer > 0) {
g_source_remove(data->sink_timer);
+ data->sink_timer = 0;
+ }
- if (data->ct_timer > 0)
+ if (data->ct_timer > 0) {
g_source_remove(data->ct_timer);
+ data->ct_timer = 0;
+ }
- if (data->tg_timer > 0)
+ if (data->tg_timer > 0) {
g_source_remove(data->tg_timer);
+ data->tg_timer = 0;
+ }
+}
+static void policy_remove(void *user_data)
+{
+ struct policy_data *data = user_data;
+
+ policy_reset(data);
g_free(data);
}
@@ -606,6 +620,11 @@ static void service_cb(struct btd_service *service,
{
struct btd_profile *profile = btd_service_get_profile(service);
struct reconnect_data *reconnect;
+ struct policy_data *policy;
+
+ policy = find_data(btd_service_get_device(service));
+ if (policy && policy->auth_failure)
+ return;
if (g_str_equal(profile->remote_uuid, A2DP_SINK_UUID))
sink_cb(service, old_state, new_state);
@@ -704,20 +723,29 @@ static void reconnect_set_timer(struct reconnect_data *reconnect)
static void disconnect_cb(struct btd_device *dev, uint8_t reason)
{
struct reconnect_data *reconnect;
+ struct policy_data *policy;
DBG("reason %u", reason);
- if (reason != MGMT_DEV_DISCONN_TIMEOUT)
- return;
-
- reconnect = reconnect_find(dev);
- if (!reconnect || !reconnect->reconnect)
- return;
+ switch (reason) {
+ case MGMT_DEV_DISCONN_AUTH_FAILURE:
+ policy = policy_get_data(dev);
+ policy_reset(policy);
+ policy->auth_failure = true;
+ break;
+ case MGMT_DEV_DISCONN_TIMEOUT:
+ reconnect = reconnect_find(dev);
+ if (!reconnect || !reconnect->reconnect)
+ break;
- DBG("Device %s identified for auto-reconnection",
+ DBG("Device %s identified for auto-reconnection",
device_get_path(dev));
- reconnect_set_timer(reconnect);
+ reconnect_set_timer(reconnect);
+ break;
+ default:
+ break;
+ }
}
static void conn_fail_cb(struct btd_device *dev, uint8_t status)
--
2.7.4
next prev parent reply other threads:[~2016-08-04 13:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-04 13:28 [RFC 0/5] Rebond support Szymon Janc
2016-08-04 13:28 ` [RFC 1/5] lib/mgmt: Add MGMT_DEV_DISCONN_AUTH_FAILURE definition Szymon Janc
2016-08-04 13:28 ` [RFC 2/5] doc: Add RebondConsent method to agent API Szymon Janc
2016-08-04 13:28 ` [RFC 3/5] core/adapter: Add support for rebond consent Szymon Janc
2016-08-04 13:28 ` Szymon Janc [this message]
2016-08-04 13:28 ` [RFC 5/5] client: Add support for RebondConsent request Szymon Janc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1470317319-3985-5-git-send-email-szymon.janc@codecoup.pl \
--to=szymon.janc@codecoup.pl \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).