Skip to contentSkip to conversation

Adding bonded flag to D-Bus property

PATCH Superseded Zhengping Jiang 3 participants 8 messages Apr 18, 2022 – May 2, 2022 1 message not in the archive Bluetooth drivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Adding bonded flag to D-Bus property

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 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 (2):
device: Add "Bonded" flag to dbus property
client: Add bonded-devices and show Bonded flag in info

 client/main.c      | 29 +++++++++++++++++++++++++++++
 doc/device-api.txt |  4 ++++
 src/device.c       | 40 +++++++++++++++++++++++++++++++++++-----
 3 files changed, 68 insertions(+), 5 deletions(-)
Signature · 1 line
2.36.0.rc0.470.gd361397f0d-goog
#1 lore raw

PATCH v2 1/2 device: Add "Bonded" flag to dbus property

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.

---

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

 doc/device-api.txt |  4 ++++
 src/device.c       | 40 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 39 insertions(+), 5 deletions(-)
doc/device-api.txt +4 -0
index 4e824d2dec17..6162755f954c 100644
@@ -171,6 +171,10 @@ Properties	string Address [readonly]
 
 			Indicates if the remote device is paired.
 
+		boolean Bonded [readonly]
+
+			Indicates if the remote device is bonded.
+
 		boolean Connected [readonly]
 
 			Indicates if the remote device is currently connected.
src/device.c +35 -5
index 8dc12d026827..868c41f025d9 100644
@@ -1042,6 +1042,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)
 {
@@ -3120,6 +3136,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 },
@@ -6114,17 +6131,30 @@ void btd_device_set_trusted(struct btd_device *device, gboolean trusted)
 
 void device_set_bonded(struct btd_device *device, uint8_t bdaddr_type)
 {
+	struct bearer_state *state;
+
 	if (!device)
 		return;
 
-	DBG("");
+	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)
Signature · 1 line
2.36.0.rc0.470.gd361397f0d-goog
#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=633121

---Test result---

Test Summary:

CheckPatch                    PASS      1.43 seconds
GitLint                       PASS      0.89 seconds
Prep - Setup ELL              PASS      49.01 seconds
Build - Prep                  PASS      0.61 seconds
Build - Configure             PASS      9.71 seconds
Build - Make                  PASS      1700.73 seconds
Make Check                    PASS      12.49 seconds
Make Check w/Valgrind         PASS      515.95 seconds
Make Distcheck                PASS      271.29 seconds
Build w/ext ELL - Configure   PASS      10.12 seconds
Build w/ext ELL - Make        PASS      1667.33 seconds
Incremental Build with patchesPASS      3404.97 seconds

---
Regards,
Linux Bluetooth

#3 lore raw

Re: [Bluez PATCH v2 1/2] device: Add "Bonded" flag to dbus property

In reply to Zhengping Jiang

Hi Zhengping,

Quoted 27 lines · Zhengping Jiang

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.

---

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

 doc/device-api.txt |  4 ++++
 src/device.c       | 40 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 39 insertions(+), 5 deletions(-)
doc/device-api.txt +0 -0
index 4e824d2dec17..6162755f954c 100644

doc/device-api.txt Properties string Address [readonly] · line 176

Quoted 6 lines
doc/device-api.txt +3 -0
@@ -171,6 +171,10 @@ Properties string Address [readonly]
 
                        Indicates if the remote device is paired.
 
+               boolean Bonded [readonly]
+
+                       Indicates if the remote device is bonded.

It is probably a good idea to add a description about Bonded vs Paired. Btw, API documentation should be in a separate patch.

Quoted 78 lines
doc/device-api.txt +1 -0
+
                boolean Connected [readonly]
 
                        Indicates if the remote device is currently connected.
src/device.c +35 -6
index 8dc12d026827..868c41f025d9 100644
@@ -1042,6 +1042,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)
 {
@@ -3120,6 +3136,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 },
@@ -6114,17 +6131,30 @@ void btd_device_set_trusted(struct btd_device *device, gboolean trusted)
 
 void device_set_bonded(struct btd_device *device, uint8_t bdaddr_type)
 {
+       struct bearer_state *state;
+
        if (!device)
                return;
 
-       DBG("");
+       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.rc0.470.gd361397f0d-goog

Signature · 1 line
Luiz Augusto von Dentz
#4 lore raw

Re: [Bluez PATCH v2 1/2] device: Add "Bonded" flag to dbus property

Hi Zhengping,

Quoted 32 lines · Luiz Augusto von Dentz

Hi Zhengping,

Quoted 28 lines · Zhengping Jiang

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.

---

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

 doc/device-api.txt |  4 ++++
 src/device.c       | 40 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 39 insertions(+), 5 deletions(-)
doc/device-api.txt +0 -0
index 4e824d2dec17..6162755f954c 100644
@@ -171,6 +171,10 @@ Properties string Address [readonly]
 
Quoted 8 lines

doc/device-api.txt Properties string Address [readonly] · line 176

Quoted 5 lines
doc/device-api.txt +3 -0
                        Indicates if the remote device is paired.
 
+               boolean Bonded [readonly]
+
+                       Indicates if the remote device is bonded.

It is probably a good idea to add a description about Bonded vs Paired. Btw, API documentation should be in a separate patch.

Will you be updating following this comments or you are waiting more feedback from upstream?

Quoted 82 lines
Quoted 76 lines
doc/device-api.txt +1 -0
+
                boolean Connected [readonly]
 
                        Indicates if the remote device is currently connected.
src/device.c +35 -6
index 8dc12d026827..868c41f025d9 100644
@@ -1042,6 +1042,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)
 {
@@ -3120,6 +3136,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 },
@@ -6114,17 +6131,30 @@ void btd_device_set_trusted(struct btd_device *device, gboolean trusted)
 
 void device_set_bonded(struct btd_device *device, uint8_t bdaddr_type)
 {
+       struct bearer_state *state;
+
        if (!device)
                return;
 
-       DBG("");
+       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)
--
Quoted 2 lines

2.36.0.rc0.470.gd361397f0d-goog

--
Luiz Augusto von Dentz

Signature · 1 line
Luiz Augusto von Dentz

A message that is not in the archive (sent off-list or not yet received): CAB4PzUpJmkXsgH_w++U0i8g_YvUbmae5n37acF3=q+3P0nJX2g@mail.gmail.com

#6 lore raw

Re: [Bluez PATCH v2 1/2] device: Add "Bonded" flag to dbus property

Hi Zhengping,

Quoted 5 lines · Zhengping Jiang

Hi Luiz,

Sorry for the delay. I just submitted a new patch for internal review. Will be sent upstream very soon.
Just to confirm, I will remove the option "paired-devices" and add optional arguments to "devices" command, so it can generate a list of devices based on filters.

Great, thanks for letting me know. And yes, I think listing devices based on filters is a better option than yet another command to list a subset of devices.

Quoted 140 lines

Thanks,
Zhengping

Quoted 136 lines · Luiz Augusto von Dentz

Hi Zhengping,

Quoted 32 lines · Luiz Augusto von Dentz

Hi Zhengping,

Quoted 28 lines · Zhengping Jiang

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.

---

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

 doc/device-api.txt |  4 ++++
 src/device.c       | 40 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 39 insertions(+), 5 deletions(-)
doc/device-api.txt +0 -0
index 4e824d2dec17..6162755f954c 100644
@@ -171,6 +171,10 @@ Properties string Address [readonly]
 
Quoted 8 lines

doc/device-api.txt Properties string Address [readonly] · line 176

Quoted 5 lines
doc/device-api.txt +3 -0
                        Indicates if the remote device is paired.
 
+               boolean Bonded [readonly]
+
+                       Indicates if the remote device is bonded.

It is probably a good idea to add a description about Bonded vs Paired. Btw, API documentation should be in a separate patch.

Will you be updating following this comments or you are waiting more feedback from upstream?

Quoted 74 lines
Quoted 74 lines
doc/device-api.txt +1 -0
+
                boolean Connected [readonly]
 
                        Indicates if the remote device is currently connected.
src/device.c +35 -5
index 8dc12d026827..868c41f025d9 100644
@@ -1042,6 +1042,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)
 {
@@ -3120,6 +3136,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 },
@@ -6114,17 +6131,30 @@ void btd_device_set_trusted(struct btd_device *device, gboolean trusted)
 
 void device_set_bonded(struct btd_device *device, uint8_t bdaddr_type)
 {
+       struct bearer_state *state;
+
        if (!device)
                return;
 
-       DBG("");
+       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");
 }
 
Quoted 8 lines
Quoted 4 lines
src/device.c +0 -1
 void device_set_legacy(struct btd_device *device, bool legacy)
--

2.36.0.rc0.470.gd361397f0d-goog

--
Luiz Augusto von Dentz

--
Luiz Augusto von Dentz

Signature · 1 line
Luiz Augusto von Dentz
#7 lore raw

PATCH v2 2/2 client: Add bonded-devices and show Bonded flag in info

In reply to Zhengping Jiang

Add "bonded-devices" to the menu and show the "Bonded" property for command "info".

---

(no changes since v1)

Changes in v1:
- Show the status of the "Bonded" flag in bluetoothctl
- Add option to show list of bonded devices

 client/main.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
client/main.c +29 -0
index 589268c3a68c..45c89a1de37b 100644
@@ -1090,6 +1090,32 @@ static void cmd_paired_devices(int argc, char *argv[])
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
+static void cmd_bonded_devices(int argc, char *argv[])
+{
+	GList *ll;
+
+	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;
+		DBusMessageIter iter;
+		dbus_bool_t bonded;
+
+		if (g_dbus_proxy_get_property(proxy, "Bonded", &iter) == FALSE)
+			continue;
+
+		dbus_message_iter_get_basic(&iter, &bonded);
+		if (!bonded)
+			continue;
+
+		print_device(proxy, NULL);
+	}
+
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
 static void generic_callback(const DBusError *error, void *user_data)
 {
 	char *str = user_data;
@@ -1781,6 +1807,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");
@@ -3116,6 +3143,8 @@ static const struct bt_shell_menu main_menu = {
 	{ "devices",      NULL,       cmd_devices, "List available devices" },
 	{ "paired-devices", NULL,     cmd_paired_devices,
 					"List paired devices"},
+	{ "bonded-devices", NULL,     cmd_bonded_devices,
+					"List bonded devices"},
 	{ "system-alias", "<name>",   cmd_system_alias,
 					"Set controller alias" },
 	{ "reset-alias",  NULL,       cmd_reset_alias,
Signature · 1 line
2.36.0.rc0.470.gd361397f0d-goog
#8 lore raw

Re: [Bluez PATCH v2 2/2] client: Add bonded-devices and show Bonded flag in info

Hi Zhengping,

Quoted 65 lines · Zhengping Jiang

Add "bonded-devices" to the menu and show the "Bonded" property for command "info".

---

(no changes since v1)

Changes in v1:
- Show the status of the "Bonded" flag in bluetoothctl
- Add option to show list of bonded devices

 client/main.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
client/main.c +27 -0
index 589268c3a68c..45c89a1de37b 100644
@@ -1090,6 +1090,32 @@ static void cmd_paired_devices(int argc, char *argv[])
        return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
+static void cmd_bonded_devices(int argc, char *argv[])
+{
+       GList *ll;
+
+       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;
+               DBusMessageIter iter;
+               dbus_bool_t bonded;
+
+               if (g_dbus_proxy_get_property(proxy, "Bonded", &iter) == FALSE)
+                       continue;
+
+               dbus_message_iter_get_basic(&iter, &bonded);
+               if (!bonded)
+                       continue;
+
+               print_device(proxy, NULL);
+       }
+
+       return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
 static void generic_callback(const DBusError *error, void *user_data)
 {
        char *str = user_data;
@@ -1781,6 +1807,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");

client/main.c static const struct bt_shell_menu main_menu = { · line 3147

Quoted 5 lines
client/main.c +2 -0
@@ -3116,6 +3143,8 @@ static const struct bt_shell_menu main_menu = {
        { "devices",      NULL,       cmd_devices, "List available devices" },
        { "paired-devices", NULL,     cmd_paired_devices,
                                        "List paired devices"},
+       { "bonded-devices", NULL,     cmd_bonded_devices,
+                                       "List bonded devices"},

I would have done it a little be different, make devices command create different lists:

bluetoothctl> devices [Trusted/Paired/Bonded/Connected] Device XX:... Name (Trusted, Paired, Bonded...)
...

That way we don't have to create a command for each possible device filter.

Quoted 6 lines
client/main.c +0 -1
        { "system-alias", "<name>",   cmd_system_alias,
                                        "Set controller alias" },
        { "reset-alias",  NULL,       cmd_reset_alias,
--

2.36.0.rc0.470.gd361397f0d-goog

Signature · 1 line
Luiz Augusto von Dentz