From: Luiz Augusto von Dentz <[email protected]>
This adds discoverable-timeout command which can be used to get/set
DiscoverableTimeout property:
[bluetooth]# discoverable-timeout 180
Changing discoverable-timeout 180 succeeded
---
client/main.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/client/main.c b/client/main.c
index 87323d8f7..59820c6d9 100644
--- a/client/main.c
+++ b/client/main.c
@@ -1061,6 +1061,47 @@ static void cmd_discoverable(int argc, char *argv[])
return bt_shell_noninteractive_quit(EXIT_FAILURE);
}
+static void cmd_discoverable_timeout(int argc, char *argv[])
+{
+ uint32_t value;
+ char *endptr = NULL;
+ char *str;
+
+ if (argc < 2) {
+ DBusMessageIter iter;
+
+ if (!g_dbus_proxy_get_property(default_ctrl->proxy,
+ "DiscoverableTimeout", &iter)) {
+ bt_shell_printf("Unable to get DiscoverableTimeout\n");
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+
+ dbus_message_iter_get_basic(&iter, &value);
+
+ bt_shell_printf("DiscoverableTimeout: %d seconds\n", value);
+
+ return;
+ }
+
+ value = strtol(argv[1], &endptr, 0);
+ if (!endptr || *endptr != '\0' || value > UINT32_MAX) {
+ bt_shell_printf("Invalid argument\n");
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+
+ str = g_strdup_printf("discoverable-timeout %d", value);
+
+ if (g_dbus_proxy_set_property_basic(default_ctrl->proxy,
+ "DiscoverableTimeout",
+ DBUS_TYPE_UINT32, &value,
+ generic_callback, str, g_free))
+ return;
+
+ g_free(str);
+
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+}
+
static void cmd_agent(int argc, char *argv[])
{
dbus_bool_t enable;
@@ -2549,6 +2590,8 @@ static const struct bt_shell_menu main_menu = {
{ "discoverable", "<on/off>", cmd_discoverable,
"Set controller discoverable mode",
NULL },
+ { "discoverable-timeout", "[value]", cmd_discoverable_timeout,
+ "Set discoverable timeout", NULL },
{ "agent", "<on/off/capability>", cmd_agent,
"Enable/disable agent with given capability",
capability_generator},
--
2.17.1
Hi,
On Thu, Jul 26, 2018 at 3:43 PM, Bastien Nocera <[email protected]> wrote:
> On Wed, 2018-07-25 at 13:20 +0300, Luiz Augusto von Dentz wrote:
>> From: Luiz Augusto von Dentz <[email protected]>
>>
>> This adds discoverable-timeout command which can be used to get/set
>> DiscoverableTimeout property:
>>
>> [bluetooth]# discoverable-timeout 180
>> Changing discoverable-timeout 180 succeeded
>
> Tested ok here.
Applied.
--
Luiz Augusto von Dentz
On Thu, 2018-07-26 at 17:19 +0300, Luiz Augusto von Dentz wrote:
> Hi,
>
> On Thu, Jul 26, 2018 at 3:43 PM, Bastien Nocera <[email protected]>
> wrote:
> > On Wed, 2018-07-25 at 13:20 +0300, Luiz Augusto von Dentz wrote:
> > > - property_set_mode_complete, data,
> > > g_free) > 0)
> > > + property_set_mode_complete, data, g_free)
> > > > 0)
> >
> > White space change is probably not needed here.
> >
> > This patch and 4/4 don't work as expected though. I use this set of
> > 2
> > commands to replicate what gnome-bluetooth did:
> >
> > dbus-send --system --dest=org.bluez /org/bluez/hci0
> > org.freedesktop.DBus.Properties.Set string:org.bluez.Adapter1
> > string:Discoverable variant:boolean:false ; dbus-send --system --
> > dest=org.bluez /org/bluez/hci0 org.freedesktop.DBus.Properties.Set
> > string:org.bluez.Adapter1 string:DiscoverableTimeout
> > variant:uint32:0
> >
> > You can add a "print-reply" which will wait for the caller to
> > return.
> > In my case, without the --print-reply, property_set_mode will never
> > be
> > called.
>
> It looks like dbus-send cannot be used since it exits immediately,
> anyway I tried by modifying bluetoothctl and it seems to be working
> properly:
>
> https://gist.github.com/Vudentz/69737e4cc236f24d33404fffc5e51ff4
I think it's a bug in bluetoothd that it would drop property change
requests when the caller goes away, but as you said, it works as
expected when both properties are called from a single, long-running,
client.
Looks good
Hi,
On Thu, Jul 26, 2018 at 3:43 PM, Bastien Nocera <[email protected]> wrote:
> On Wed, 2018-07-25 at 13:20 +0300, Luiz Augusto von Dentz wrote:
>> - property_set_mode_complete, data, g_free) > 0)
>> + property_set_mode_complete, data, g_free) > 0)
>
> White space change is probably not needed here.
>
> This patch and 4/4 don't work as expected though. I use this set of 2
> commands to replicate what gnome-bluetooth did:
>
> dbus-send --system --dest=org.bluez /org/bluez/hci0
> org.freedesktop.DBus.Properties.Set string:org.bluez.Adapter1
> string:Discoverable variant:boolean:false ; dbus-send --system --
> dest=org.bluez /org/bluez/hci0 org.freedesktop.DBus.Properties.Set
> string:org.bluez.Adapter1 string:DiscoverableTimeout variant:uint32:0
>
> You can add a "print-reply" which will wait for the caller to return.
> In my case, without the --print-reply, property_set_mode will never be
> called.
It looks like dbus-send cannot be used since it exits immediately,
anyway I tried by modifying bluetoothctl and it seems to be working
properly:
https://gist.github.com/Vudentz/69737e4cc236f24d33404fffc5e51ff4
--
Luiz Augusto von Dentz
On Wed, 2018-07-25 at 13:20 +0300, Luiz Augusto von Dentz wrote:
> - property_set_mode_complete, data, g_free) > 0)
> + property_set_mode_complete, data, g_free) > 0)
White space change is probably not needed here.
This patch and 4/4 don't work as expected though. I use this set of 2
commands to replicate what gnome-bluetooth did:
dbus-send --system --dest=org.bluez /org/bluez/hci0
org.freedesktop.DBus.Properties.Set string:org.bluez.Adapter1
string:Discoverable variant:boolean:false ; dbus-send --system --
dest=org.bluez /org/bluez/hci0 org.freedesktop.DBus.Properties.Set
string:org.bluez.Adapter1 string:DiscoverableTimeout variant:uint32:0
You can add a "print-reply" which will wait for the caller to return.
In my case, without the --print-reply, property_set_mode will never be
called.
On Wed, 2018-07-25 at 13:20 +0300, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> This adds discoverable-timeout command which can be used to get/set
> DiscoverableTimeout property:
>
> [bluetooth]# discoverable-timeout 180
> Changing discoverable-timeout 180 succeeded
Tested ok here.
On Wed, 2018-07-25 at 13:20 +0300, Luiz Augusto von Dentz wrote:
> DiscoverableTimeout: 0x00000000
That seems to work, but an hex number is pretty useless here. Could you
special case DiscoverableTimeout in print_property to show a base-10
integer instead?
From: Luiz Augusto von Dentz <[email protected]>
This makes DiscoverableTimeout check if discoverable is already pending
and don't attempt to set it once again which may cause discoverable to
be re-enabled when in fact the application just want to set the timeout
alone.
---
src/adapter.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/adapter.c b/src/adapter.c
index 20c20f9e9..f92c897c7 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2901,6 +2901,7 @@ static void property_set_discoverable_timeout(
GDBusPendingPropertySet id, void *user_data)
{
struct btd_adapter *adapter = user_data;
+ bool enabled;
dbus_uint32_t value;
dbus_message_iter_get_basic(iter, &value);
@@ -2914,8 +2915,19 @@ static void property_set_discoverable_timeout(
g_dbus_emit_property_changed(dbus_conn, adapter->path,
ADAPTER_INTERFACE, "DiscoverableTimeout");
+ if (adapter->pending_settings & MGMT_SETTING_DISCOVERABLE) {
+ if (adapter->current_settings & MGMT_SETTING_DISCOVERABLE)
+ enabled = false;
+ else
+ enabled = true;
+ } else {
+ if (adapter->current_settings & MGMT_SETTING_DISCOVERABLE)
+ enabled = true;
+ else
+ enabled = false;
+ }
- if (adapter->current_settings & MGMT_SETTING_DISCOVERABLE)
+ if (enabled)
set_discoverable(adapter, 0x01, adapter->discoverable_timeout);
}
--
2.17.1
From: Luiz Augusto von Dentz <[email protected]>
This tracks settings being changed and in case the settings is already
pending considered it to be done.
---
src/adapter.c | 30 ++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index af340fd6e..20c20f9e9 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -196,6 +196,7 @@ struct btd_adapter {
char *name; /* controller device name */
char *short_name; /* controller short name */
uint32_t supported_settings; /* controller supported settings */
+ uint32_t pending_settings; /* pending controller settings */
uint32_t current_settings; /* current controller settings */
char *path; /* adapter object path */
@@ -509,8 +510,10 @@ static void settings_changed(struct btd_adapter *adapter, uint32_t settings)
changed_mask = adapter->current_settings ^ settings;
adapter->current_settings = settings;
+ adapter->pending_settings &= ~changed_mask;
DBG("Changed settings: 0x%08x", changed_mask);
+ DBG("Pending settings: 0x%08x", adapter->pending_settings);
if (changed_mask & MGMT_SETTING_POWERED) {
g_dbus_emit_property_changed(dbus_conn, adapter->path,
@@ -596,10 +599,31 @@ static bool set_mode(struct btd_adapter *adapter, uint16_t opcode,
uint8_t mode)
{
struct mgmt_mode cp;
+ uint32_t setting = 0;
memset(&cp, 0, sizeof(cp));
cp.val = mode;
+ switch (mode) {
+ case MGMT_OP_SET_POWERED:
+ setting = MGMT_SETTING_POWERED;
+ break;
+ case MGMT_OP_SET_CONNECTABLE:
+ setting = MGMT_SETTING_CONNECTABLE;
+ break;
+ case MGMT_OP_SET_FAST_CONNECTABLE:
+ setting = MGMT_SETTING_FAST_CONNECTABLE;
+ break;
+ case MGMT_OP_SET_DISCOVERABLE:
+ setting = MGMT_SETTING_DISCOVERABLE;
+ break;
+ case MGMT_OP_SET_BONDABLE:
+ setting = MGMT_SETTING_DISCOVERABLE;
+ break;
+ }
+
+ adapter->pending_settings |= setting;
+
DBG("sending set mode command for index %u", adapter->dev_id);
if (mgmt_send(adapter->mgmt, opcode,
@@ -2739,13 +2763,15 @@ static void property_set_mode(struct btd_adapter *adapter, uint32_t setting,
else
current_enable = FALSE;
- if (enable == current_enable) {
+ if (enable == current_enable || adapter->pending_settings & setting) {
g_dbus_pending_property_success(id);
return;
}
mode = (enable == TRUE) ? 0x01 : 0x00;
+ adapter->pending_settings |= setting;
+
switch (setting) {
case MGMT_SETTING_POWERED:
opcode = MGMT_OP_SET_POWERED;
@@ -2798,7 +2824,7 @@ static void property_set_mode(struct btd_adapter *adapter, uint32_t setting,
data->id = id;
if (mgmt_send(adapter->mgmt, opcode, adapter->dev_id, len, param,
- property_set_mode_complete, data, g_free) > 0)
+ property_set_mode_complete, data, g_free) > 0)
return;
g_free(data);
--
2.17.1
From: Luiz Augusto von Dentz <[email protected]>
Controller XX:XX:XX:XX:XX:XX (public)
Name: Vudentz's T460s
Alias: Intel-1
Class: 0x004c010c
Powered: yes
Discoverable: no
DiscoverableTimeout: 0x00000000
Pairable: yes
UUID: Headset AG (00001112-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
UUID: SIM Access (0000112d-0000-1000-8000-00805f9b34fb)
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb)
UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb)
UUID: Headset (00001108-0000-1000-8000-00805f9b34fb)
Modalias: usb:v1D6Bp0246d0532
Discovering: no
---
client/main.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/client/main.c b/client/main.c
index 59820c6d9..6f472d050 100644
--- a/client/main.c
+++ b/client/main.c
@@ -877,6 +877,7 @@ static void cmd_show(int argc, char *argv[])
print_property(proxy, "Class");
print_property(proxy, "Powered");
print_property(proxy, "Discoverable");
+ print_property(proxy, "DiscoverableTimeout");
print_property(proxy, "Pairable");
print_uuids(proxy);
print_property(proxy, "Modalias");
--
2.17.1