diff mbox series

[v2,2/2] device: Fix not setting initiator flag when auto-connecting

Message ID 20230329232537.577958-2-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Commit 2b022fa5297a56875f06c2b5612258cd99dcbe74
Headers show
Series [v2,1/2] bap: Mark devices to auto-connect | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Luiz Augusto von Dentz March 29, 2023, 11:25 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

If the device is marked as auto-connect the kernel may initiate the
connection spontaneously causing new connections to not have set the
state->initiator flag properly.
---
 src/device.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/device.c b/src/device.c
index f31f2a097e07..b43ced8b5c91 100644
--- a/src/device.c
+++ b/src/device.c
@@ -312,9 +312,16 @@  static struct bearer_state *get_state(struct btd_device *dev,
 
 bool btd_device_is_initiator(struct btd_device *dev)
 {
-	if (dev->le_state.connected)
+	if (dev->le_state.connected) {
+		/* Mark as initiator if not set yet and auto-connect flag is
+		 * set and LTK key is for a peripheral.
+		 */
+		if (!dev->le_state.initiator && dev->auto_connect &&
+					dev->ltk && !dev->ltk->central)
+			dev->le_state.initiator = true;
+
 		return dev->le_state.initiator;
-	if (dev->bredr_state.connected)
+	} else if (dev->bredr_state.connected)
 		return dev->bredr_state.initiator;
 
 	return dev->att_io ? true : false;