From: Szymon Janc <szymon.janc@codecoup.pl>
To: linux-bluetooth@vger.kernel.org
Cc: Szymon Janc <szymon.janc@codecoup.pl>
Subject: [PATCH v2] adapter: Fix not clearing connectable setting on power off
Date: Mon, 19 Feb 2018 13:43:35 +0100 [thread overview]
Message-ID: <20180219124335.16528-1-szymon.janc@codecoup.pl> (raw)
When kernel control of connectable is used daemon doesn't enable
connectable setting unless discoverable. Both settings are permanent
over power toggle unless discoverable timeout was set. In that case
discoverable flag is cleared by kernel on power off. This leads to
connectable flag being left enabled when toggling power on discoverable
adapter with timeout set.
This has some implications on system behaviour:
- accepting connection from unknown devices
- not being able to advertise as broadcaster
Since kernel doens't know the reason for enabling connectable flag (and
thus if disable if on power off) this needs to be handled in bluetoothd.
---
src/adapter.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/src/adapter.c b/src/adapter.c
index fcb102411..fc4913e71 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2694,6 +2694,30 @@ static void property_set_mode_complete(uint8_t status, uint16_t length,
new_settings_callback(adapter->dev_id, length, param, adapter);
}
+static void clear_discoverable(struct btd_adapter *adapter)
+{
+ if (!kernel_conn_control)
+ return;
+
+ if (!(adapter->current_settings & MGMT_SETTING_DISCOVERABLE))
+ return;
+
+ /* If no timeout is set do nothing as both connectable and discoverable
+ * flags are persistent on power toggle.
+ */
+ if (!adapter->discoverable_timeout)
+ return;
+
+ /* If timeout was set kernel clears discoverable on its own when
+ * powering off controller. This would leave connectable flag set
+ * after power on.
+ *
+ * With kernel control clearing connectable clear also discoverable
+ * flag so we need to clear connectable.
+ */
+ set_mode(adapter, MGMT_OP_SET_CONNECTABLE, 0x00);
+}
+
static void property_set_mode(struct btd_adapter *adapter, uint32_t setting,
DBusMessageIter *value,
GDBusPendingPropertySet id)
@@ -2724,6 +2748,10 @@ static void property_set_mode(struct btd_adapter *adapter, uint32_t setting,
opcode = MGMT_OP_SET_POWERED;
param = &mode;
len = sizeof(mode);
+
+ if (!mode)
+ clear_discoverable(adapter);
+
break;
case MGMT_SETTING_DISCOVERABLE:
if (kernel_conn_control) {
@@ -8756,6 +8784,7 @@ void adapter_shutdown(void)
if (!(adapter->current_settings & MGMT_SETTING_POWERED))
continue;
+ clear_discoverable(adapter);
set_mode(adapter, MGMT_OP_SET_POWERED, 0x00);
adapter_remaining++;
--
2.14.3
next reply other threads:[~2018-02-19 12:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-19 12:43 Szymon Janc [this message]
2018-02-19 17:16 ` [PATCH v2] adapter: Fix not clearing connectable setting on power off Johan Hedberg
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=20180219124335.16528-1-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).