diff mbox series

[Bluez] device: Check both bearers's paired status upon removal of connection

Message ID 20210923161816.Bluez.1.I2d4be6229452939310ccd165bc949c0f6708dd20@changeid (mailing list archive)
State Accepted
Delegated to: Luiz Von Dentz
Headers show
Series [Bluez] device: Check both bearers's paired status upon removal of connection | expand

Checks

Context Check Description
tedd_an/checkpatch success Checkpatch PASS
tedd_an/gitlint success Gitlint PASS
tedd_an/setupell success Setup ELL PASS
tedd_an/buildprep success Build Prep PASS
tedd_an/build success Build Configuration PASS
tedd_an/makecheck success Make Check PASS
tedd_an/makedistcheck success Make Distcheck PASS
tedd_an/build_extell success Build External ELL PASS
tedd_an/build_extell_make success Build Make with External ELL PASS

Commit Message

Archie Pusaka Sept. 23, 2021, 8:18 a.m. UTC
From: Archie Pusaka <apusaka@chromium.org>

Because Link Key for BREDR can be transformed into LTK for LE (and
vice versa), there is a possibility of getting 'paired' on either of
BREDR/LE without actually connected using the aforementioned bearer.

When removing the connection, we should check both bearers's paired
and bonded status rather than just the one getting disconnected.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
---

 src/device.c | 40 ++++++++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 12 deletions(-)

Comments

bluez.test.bot@gmail.com Sept. 23, 2021, 8:41 a.m. UTC | #1
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=551527

---Test result---

Test Summary:
CheckPatch                    PASS      1.54 seconds
GitLint                       PASS      0.95 seconds
Prep - Setup ELL              PASS      52.48 seconds
Build - Prep                  PASS      0.47 seconds
Build - Configure             PASS      9.60 seconds
Build - Make                  PASS      221.38 seconds
Make Check                    PASS      10.32 seconds
Make Distcheck                PASS      263.71 seconds
Build w/ext ELL - Configure   PASS      9.62 seconds
Build w/ext ELL - Make        PASS      208.63 seconds



---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz Sept. 24, 2021, 12:16 a.m. UTC | #2
Hi Archie,


On Thu, Sep 23, 2021 at 1:43 AM <bluez.test.bot@gmail.com> wrote:
>
> 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=551527
>
> ---Test result---
>
> Test Summary:
> CheckPatch                    PASS      1.54 seconds
> GitLint                       PASS      0.95 seconds
> Prep - Setup ELL              PASS      52.48 seconds
> Build - Prep                  PASS      0.47 seconds
> Build - Configure             PASS      9.60 seconds
> Build - Make                  PASS      221.38 seconds
> Make Check                    PASS      10.32 seconds
> Make Distcheck                PASS      263.71 seconds
> Build w/ext ELL - Configure   PASS      9.62 seconds
> Build w/ext ELL - Make        PASS      208.63 seconds
>
>
>
> ---
> Regards,
> Linux Bluetooth

Applied, thanks.
diff mbox series

Patch

diff --git a/src/device.c b/src/device.c
index b29aa195d1..6a66fc9a23 100644
--- a/src/device.c
+++ b/src/device.c
@@ -3010,6 +3010,7 @@  void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type)
 	struct bearer_state *state = get_state(device, bdaddr_type);
 	DBusMessage *reply;
 	bool remove_device = false;
+	bool paired_status_updated = false;
 
 	if (!state->connected)
 		return;
@@ -3048,18 +3049,33 @@  void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type)
 		dbus_message_unref(msg);
 	}
 
-	if (state->paired && !state->bonded) {
-		btd_adapter_remove_bonding(device->adapter, &device->bdaddr,
-								bdaddr_type);
-
-		state->paired = false;
-
-		/* report change only if both bearers are unpaired */
-		if (!device->bredr_state.paired && !device->le_state.paired)
-			g_dbus_emit_property_changed(dbus_conn, device->path,
-							DEVICE_INTERFACE,
-							"Paired");
-	}
+	/* Check paired status of both bearers since it's possible to be
+	 * paired but not connected via link key to LTK conversion.
+	 */
+	if (!device->bredr_state.connected && device->bredr_state.paired &&
+						!device->bredr_state.bonded) {
+		btd_adapter_remove_bonding(device->adapter,
+						&device->bdaddr,
+						BDADDR_BREDR);
+		device->bredr_state.paired = false;
+		paired_status_updated = true;
+	}
+
+	if (!device->le_state.connected && device->le_state.paired &&
+						!device->le_state.bonded) {
+		btd_adapter_remove_bonding(device->adapter,
+						&device->bdaddr,
+						device->bdaddr_type);
+		device->le_state.paired = false;
+		paired_status_updated = true;
+	}
+
+	/* report change only if both bearers are unpaired */
+	if (!device->bredr_state.paired && !device->le_state.paired &&
+							paired_status_updated)
+		g_dbus_emit_property_changed(dbus_conn, device->path,
+						DEVICE_INTERFACE,
+						"Paired");
 
 	if (device->bredr_state.connected || device->le_state.connected)
 		return;