Currently BlueZ client can't know easily whether a device is bonded or
not. This is causing issues for a number of applications. For example,
in the Nearby Share case, the peer device is paired, but not bonded.
This series will add the "Bonded" property in org.bluez.Device1 D-Bus
interface. Changes are also made in bluetoothctl to show the status of
the bonded flag as well as a list of bonded devices.
Changes in v3:
- Move documentation update to a separate patch
- Add description to bonded and paired
- Add an optional argument to the devices command to filter device list
- Remove paired-devices command
Changes in v2:
- Move one variable declaration to the top following C90 standard
Changes in v1:
- Add "Bonded" to D-Bus interface
- Send property changed signal if the bonded flag is changed
- Show the status of the "Bonded" flag in bluetoothctl
- Add option to show list of bonded devices
Zhengping Jiang (3):
device: Add "Bonded" flag to dbus property
doc: add "Bonded" flag to dbus property
client: Add filter to devices and show Bonded in info
client/main.c | 72 ++++++++++++++++++++++++++++++----------------
doc/device-api.txt | 12 +++++++-
src/device.c | 38 ++++++++++++++++++++----
3 files changed, 91 insertions(+), 31 deletions(-)
--
2.36.0.464.gb9c8b46e94-goog
Hi Zhengping,
On Wed, May 4, 2022 at 2:54 PM Zhengping Jiang <[email protected]> wrote:
>
> Hi Luiz,
>
> Sorry for the error. It should have been fixed in patch 2. I think I updated the wrong version.
Don't worry, I'm fixing it myself.
> Thanks,
> Zhengping
>
> On Wed, May 4, 2022 at 2:49 PM Luiz Augusto von Dentz <[email protected]> wrote:
>>
>> Hi Zhengping,
>>
>> On Wed, May 4, 2022 at 2:09 PM Zhengping Jiang <[email protected]> wrote:
>> >
>> > Currently BlueZ client can't know easily whether a device is bonded or
>> > not. This is causing issues for a number of applications. For example,
>> > in the Nearby Share case, the peer device is paired, but not bonded.
>> > This series will add the "Bonded" property in org.bluez.Device1 D-Bus
>> > interface. Changes are also made in bluetoothctl to show the status of
>> > the bonded flag as well as a list of bonded devices.
>> >
>> > Changes in v3:
>> > - Move documentation update to a separate patch
>> > - Add description to bonded and paired
>> > - Add an optional argument to the devices command to filter device list
>> > - Remove paired-devices command
>> >
>> > Changes in v2:
>> > - Move one variable declaration to the top following C90 standard
>> >
>> > Changes in v1:
>> > - Add "Bonded" to D-Bus interface
>> > - Send property changed signal if the bonded flag is changed
>> > - Show the status of the "Bonded" flag in bluetoothctl
>> > - Add option to show list of bonded devices
>> >
>> > Zhengping Jiang (3):
>> > device: Add "Bonded" flag to dbus property
>> > doc: add "Bonded" flag to dbus property
>> > client: Add filter to devices and show Bonded in info
>> >
>> > client/main.c | 72 ++++++++++++++++++++++++++++++----------------
>> > doc/device-api.txt | 12 +++++++-
>> > src/device.c | 38 ++++++++++++++++++++----
>> > 3 files changed, 91 insertions(+), 31 deletions(-)
>> >
>> > --
>> > 2.36.0.464.gb9c8b46e94-goog
>>
>> src/device.c: In function ‘device_set_bonded’:
>> src/device.c:6141:9: error: ISO C90 forbids mixed declarations and
>> code [-Werror=declaration-after-statement]
>> 6141 | struct bearer_state *state = get_state(device, bdaddr_type);
>> |
>>
>>
>> --
>> Luiz Augusto von Dentz
--
Luiz Augusto von Dentz
Add "Bonded" to dbus device property table. When setting the "Bonded
flag, check the status of the Bonded property first. If the Bonded
property is changed, send property changed signal.
Reviewed-by: Sonny Sasaka <[email protected]>
Reviewed-by: Yun-Hao Chung <[email protected]>
Signed-off-by: Zhengping Jiang <[email protected]>
---
(no changes since v2)
Changes in v2:
- Move one variable declaration to the top following C90 standard
Changes in v1:
- Add "Bonded" to D-Bus interface
- Send property changed signal if the bonded flag is changed
src/device.c | 38 +++++++++++++++++++++++++++++++++-----
1 file changed, 33 insertions(+), 5 deletions(-)
diff --git a/src/device.c b/src/device.c
index a62564b14f49..72804713b25b 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1143,6 +1143,22 @@ static gboolean dev_property_get_paired(const GDBusPropertyTable *property,
return TRUE;
}
+static gboolean dev_property_get_bonded(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct btd_device *dev = data;
+ dbus_bool_t val;
+
+ if (dev->bredr_state.bonded || dev->le_state.bonded)
+ val = TRUE;
+ else
+ val = FALSE;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &val);
+
+ return TRUE;
+}
+
static gboolean dev_property_get_legacy(const GDBusPropertyTable *property,
DBusMessageIter *iter, void *data)
{
@@ -4033,6 +4049,7 @@ static const GDBusPropertyTable device_properties[] = {
{ "Icon", "s", dev_property_get_icon, NULL,
dev_property_exists_icon },
{ "Paired", "b", dev_property_get_paired },
+ { "Bonded", "b", dev_property_get_bonded },
{ "Trusted", "b", dev_property_get_trusted, dev_property_set_trusted },
{ "Blocked", "b", dev_property_get_blocked, dev_property_set_blocked },
{ "LegacyPairing", "b", dev_property_get_legacy },
@@ -7065,14 +7082,25 @@ void device_set_bonded(struct btd_device *device, uint8_t bdaddr_type)
if (!device)
return;
- DBG("");
+ struct bearer_state *state = get_state(device, bdaddr_type);
- if (bdaddr_type == BDADDR_BREDR)
- device->bredr_state.bonded = true;
- else
- device->le_state.bonded = true;
+ if (state->bonded)
+ return;
+
+ DBG("setting bonded for device to true");
+
+ state->bonded = true;
btd_device_set_temporary(device, false);
+
+ /* If the other bearer state was already true we don't need to
+ * send any property signals.
+ */
+ if (device->bredr_state.bonded == device->le_state.bonded)
+ return;
+
+ g_dbus_emit_property_changed(dbus_conn, device->path,
+ DEVICE_INTERFACE, "Bonded");
}
void device_set_legacy(struct btd_device *device, bool legacy)
--
2.36.0.464.gb9c8b46e94-goog
Hello:
This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <[email protected]>:
On Wed, 4 May 2022 14:09:45 -0700 you wrote:
> Currently BlueZ client can't know easily whether a device is bonded or
> not. This is causing issues for a number of applications. For example,
> in the Nearby Share case, the peer device is paired, but not bonded.
> This series will add the "Bonded" property in org.bluez.Device1 D-Bus
> interface. Changes are also made in bluetoothctl to show the status of
> the bonded flag as well as a list of bonded devices.
>
> [...]
Here is the summary with links:
- [Bluez,v3,1/3] device: Add "Bonded" flag to dbus property
(no matching commit)
- [Bluez,v3,2/3] doc: add "Bonded" flag to dbus property
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5c05df7c7607
- [Bluez,v3,3/3] client: Add filter to devices and show Bonded in info
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=bda2a9e6f902
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Use the property name as optional filters to the command "devices" and
show the "Bonded" property for the command "info".
Reviewed-by: Sonny Sasaka <[email protected]>
Reviewed-by: Yun-Hao Chung <[email protected]>
Signed-off-by: Zhengping Jiang <[email protected]>
---
Changes in v3:
- Add an optional argument to the devices command to filter device list
- Remove paired-devices command
Changes in v1:
- Show the status of the "Bonded" flag in bluetoothctl
- Add option to show list of bonded devices
client/main.c | 72 +++++++++++++++++++++++++++++++++------------------
1 file changed, 47 insertions(+), 25 deletions(-)
diff --git a/client/main.c b/client/main.c
index 29a2f882e5c8..58678224f93f 100644
--- a/client/main.c
+++ b/client/main.c
@@ -95,6 +95,14 @@ static const char *ad_arguments[] = {
NULL
};
+static const char * const device_arguments[] = {
+ "Paired",
+ "Bonded",
+ "Trusted",
+ "Connected",
+ NULL
+};
+
static void proxy_leak(gpointer data)
{
printf("Leaking proxy %p\n", data);
@@ -929,6 +937,28 @@ static gboolean check_default_ctrl(void)
return TRUE;
}
+static gboolean parse_argument_devices(int argc, char *argv[],
+ const char * const *arg_table,
+ const char **option)
+{
+ const char * const *opt;
+
+ if (argc < 2) {
+ *option = NULL;
+ return TRUE;
+ }
+
+ for (opt = arg_table; opt && *opt; opt++) {
+ if (strcmp(argv[1], *opt) == 0) {
+ *option = *opt;
+ return TRUE;
+ }
+ }
+
+ bt_shell_printf("Invalid argument %s\n", argv[1]);
+ return FALSE;
+}
+
static gboolean parse_argument(int argc, char *argv[], const char **arg_table,
const char *msg, dbus_bool_t *value,
const char **option)
@@ -1068,22 +1098,11 @@ static void cmd_select(int argc, char *argv[])
static void cmd_devices(int argc, char *argv[])
{
GList *ll;
+ const char *property;
- if (check_default_ctrl() == FALSE)
- return bt_shell_noninteractive_quit(EXIT_SUCCESS);
-
- for (ll = g_list_first(default_ctrl->devices);
- ll; ll = g_list_next(ll)) {
- GDBusProxy *proxy = ll->data;
- print_device(proxy, NULL);
- }
-
- return bt_shell_noninteractive_quit(EXIT_SUCCESS);
-}
-
-static void cmd_paired_devices(int argc, char *argv[])
-{
- GList *ll;
+ if (!parse_argument_devices(argc, argv, device_arguments,
+ &property))
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
if (check_default_ctrl() == FALSE)
return bt_shell_noninteractive_quit(EXIT_SUCCESS);
@@ -1092,15 +1111,17 @@ static void cmd_paired_devices(int argc, char *argv[])
ll; ll = g_list_next(ll)) {
GDBusProxy *proxy = ll->data;
DBusMessageIter iter;
- dbus_bool_t paired;
+ dbus_bool_t status;
- if (g_dbus_proxy_get_property(proxy, "Paired", &iter) == FALSE)
- continue;
-
- dbus_message_iter_get_basic(&iter, &paired);
- if (!paired)
- continue;
+ if (property) {
+ if (g_dbus_proxy_get_property(proxy,
+ property, &iter) == FALSE)
+ continue;
+ dbus_message_iter_get_basic(&iter, &status);
+ if (!status)
+ continue;
+ }
print_device(proxy, NULL);
}
@@ -1787,6 +1808,7 @@ static void cmd_info(int argc, char *argv[])
print_property(proxy, "Appearance");
print_property(proxy, "Icon");
print_property(proxy, "Paired");
+ print_property(proxy, "Bonded");
print_property(proxy, "Trusted");
print_property(proxy, "Blocked");
print_property(proxy, "Connected");
@@ -3170,9 +3192,9 @@ static const struct bt_shell_menu main_menu = {
ctrl_generator },
{ "select", "<ctrl>", cmd_select, "Select default controller",
ctrl_generator },
- { "devices", NULL, cmd_devices, "List available devices" },
- { "paired-devices", NULL, cmd_paired_devices,
- "List paired devices"},
+ { "devices", "[Paired/Bonded/Trusted/Connected]", cmd_devices,
+ "List available devices, with an "
+ "optional property as the filter" },
{ "system-alias", "<name>", cmd_system_alias,
"Set controller alias" },
{ "reset-alias", NULL, cmd_reset_alias,
--
2.36.0.464.gb9c8b46e94-goog
Hi Zhengping,
On Wed, May 4, 2022 at 2:09 PM Zhengping Jiang <[email protected]> wrote:
>
> Currently BlueZ client can't know easily whether a device is bonded or
> not. This is causing issues for a number of applications. For example,
> in the Nearby Share case, the peer device is paired, but not bonded.
> This series will add the "Bonded" property in org.bluez.Device1 D-Bus
> interface. Changes are also made in bluetoothctl to show the status of
> the bonded flag as well as a list of bonded devices.
>
> Changes in v3:
> - Move documentation update to a separate patch
> - Add description to bonded and paired
> - Add an optional argument to the devices command to filter device list
> - Remove paired-devices command
>
> Changes in v2:
> - Move one variable declaration to the top following C90 standard
>
> Changes in v1:
> - Add "Bonded" to D-Bus interface
> - Send property changed signal if the bonded flag is changed
> - Show the status of the "Bonded" flag in bluetoothctl
> - Add option to show list of bonded devices
>
> Zhengping Jiang (3):
> device: Add "Bonded" flag to dbus property
> doc: add "Bonded" flag to dbus property
> client: Add filter to devices and show Bonded in info
>
> client/main.c | 72 ++++++++++++++++++++++++++++++----------------
> doc/device-api.txt | 12 +++++++-
> src/device.c | 38 ++++++++++++++++++++----
> 3 files changed, 91 insertions(+), 31 deletions(-)
>
> --
> 2.36.0.464.gb9c8b46e94-goog
src/device.c: In function ‘device_set_bonded’:
src/device.c:6141:9: error: ISO C90 forbids mixed declarations and
code [-Werror=declaration-after-statement]
6141 | struct bearer_state *state = get_state(device, bdaddr_type);
|
--
Luiz Augusto von Dentz