2018-02-08 15:46:38

by Szymon Janc

[permalink] [raw]
Subject: [PATCH] adapter: Fix not clearing connectable setting on power off

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 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 | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index 93e36d00d..cba2aa3b5 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2693,6 +2693,22 @@ 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 timeout was set kernel clears discoverable on its own */
+ if (!adapter->discoverable_timeout)
+ return;
+
+ /* with kernel control clearing connectable clear also discoverable */
+ set_mode(adapter, MGMT_OP_SET_CONNECTABLE, 0x00);
+}
+
static void property_set_mode(struct btd_adapter *adapter, uint32_t setting,
DBusMessageIter *value,
GDBusPendingPropertySet id)
@@ -2723,6 +2739,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) {
@@ -8744,6 +8764,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



2018-02-19 09:21:57

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCH] adapter: Fix not clearing connectable setting on power off

Hi Johan,

On Friday, 16 February 2018 20:17:49 CET Johan Hedberg wrote:
> Hi Szymon,
>
> On Thu, Feb 08, 2018, Szymon Janc wrote:
> > + /* if timeout was set kernel clears discoverable on its own */
> > + if (!adapter->discoverable_timeout)
> > + return;
>
> Isn't this condition inverted? I.e. you want to call Set Connectable if
> the timeout is 0?

No, the check is correct but comment should be better I suppose.

The thing is that with timeout enabled kernel will clear only discoverable
flag leaving connectabled enabled. If timeout is not set both flags are
persistent over power toggle (which is OK). So intention of this patch is to
fix 'dangling' connectable flag in case of powering off discoverable adapter
with timeout set.

I'll send V2 with udpated comment.

--
pozdrawiam
Szymon Janc



2018-02-16 19:17:49

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH] adapter: Fix not clearing connectable setting on power off

Hi Szymon,

On Thu, Feb 08, 2018, Szymon Janc wrote:
> + /* if timeout was set kernel clears discoverable on its own */
> + if (!adapter->discoverable_timeout)
> + return;

Isn't this condition inverted? I.e. you want to call Set Connectable if
the timeout is 0?

Johan