Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH v1] Bluetooth: hci_event: Fix not emitting Device Connected event
@ 2026-12-03 20:50 Luiz Augusto von Dentz
  2026-12-04  2:10 ` [v1] " bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2026-12-03 20:50 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

If the remote initiates the connection and requests authentication
early, the Encryption Change event may arrive before Read Remote
Supported Features Complete. hci_encrypt_cfm() then moves the
connection from BT_CONFIG to BT_CONNECTED, and hci_remote_features_evt()
bails out since the state is no longer BT_CONFIG, so the path leading
to mgmt_device_connected() is never taken and MGMT_EV_DEVICE_CONNECTED
is never emitted. Userspace then services the connection without
knowing it exists ("Authorization request for non-connected device!?")
and Device1.Connected stays false.

Fix this by emitting MGMT_EV_DEVICE_CONNECTED from hci_connect_cfm()
once an ACL/LE connection reaches BT_CONNECTED, which covers every
place setting that state. To not lose the remote name in the regular
flow, where BT_CONNECTED is set while the Remote Name Request is still
outstanding, track the pending request with HCI_CONN_NAME_PEND and
leave the event to hci_check_pending_name() in that case.

Link: https://github.com/bluez/bluez/issues/2485
Fixes: 7967dc8f797f ("Bluetooth: hci_core: Fix calling mgmt_device_connected")
Assisted-by: OpenCode:claude-opus-5.5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
 include/net/bluetooth/hci_core.h | 15 +++++++++++++++
 net/bluetooth/hci_event.c        | 11 +++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 4aa0b49ae104..1d0d4fe2e1ac 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -733,6 +733,7 @@ enum {
 	HCI_CONN_PA_SYNC,
 	HCI_CONN_PA_SYNC_FAILED,
 	HCI_CONN_ENC_KEY_SIZE_PEND,
+	HCI_CONN_NAME_PEND,
 
 	__HCI_CONN_NUM_FLAGS,
 };
@@ -2272,10 +2273,24 @@ struct hci_cb {
 	void (*role_switch_cfm)	(struct hci_conn *conn, __u8 status, __u8 role);
 };
 
+void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
+			   u8 *name, u8 name_len);
+
 static inline void hci_connect_cfm(struct hci_conn *conn, __u8 status)
 {
 	struct hci_cb *cb;
 
+	/* Make sure MGMT_EV_DEVICE_CONNECTED is emitted once the connection
+	 * reaches BT_CONNECTED regardless of the order events were received
+	 * (e.g. Encryption Change before Read Remote Features Complete on
+	 * remote initiated connections). If a remote name request is pending
+	 * the event is deferred to hci_check_pending_name().
+	 */
+	if (!status && conn->state == BT_CONNECTED &&
+	    (conn->type == ACL_LINK || conn->type == LE_LINK) &&
+	    !test_bit(HCI_CONN_NAME_PEND, conn->flags))
+		mgmt_device_connected(conn->hdev, conn, NULL, 0);
+
 	mutex_lock(&hci_cb_list_lock);
 	list_for_each_entry(cb, &hci_cb_list, list) {
 		if (cb->connect_cfm)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 749963d0ce77..3e340c7cf6d8 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2567,6 +2567,9 @@ static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn,
 	 * Only those in BT_CONFIG or BT_CONNECTED states can be
 	 * considered connected.
 	 */
+	if (conn)
+		clear_bit(HCI_CONN_NAME_PEND, conn->flags);
+
 	if (conn && (conn->state == BT_CONFIG || conn->state == BT_CONNECTED))
 		mgmt_device_connected(hdev, conn, name, name_len);
 
@@ -4111,7 +4114,9 @@ static void hci_remote_features_evt(struct hci_dev *hdev, void *data,
 		memset(&cp, 0, sizeof(cp));
 		bacpy(&cp.bdaddr, &conn->dst);
 		cp.pscan_rep_mode = 0x02;
-		hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
+		if (!hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp),
+				  &cp))
+			set_bit(HCI_CONN_NAME_PEND, conn->flags);
 	} else {
 		mgmt_device_connected(hdev, conn, NULL, 0);
 	}
@@ -5555,7 +5560,9 @@ static void hci_remote_ext_features_evt(struct hci_dev *hdev, void *data,
 		memset(&cp, 0, sizeof(cp));
 		bacpy(&cp.bdaddr, &conn->dst);
 		cp.pscan_rep_mode = 0x02;
-		hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
+		if (!hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp),
+				  &cp))
+			set_bit(HCI_CONN_NAME_PEND, conn->flags);
 	} else {
 		mgmt_device_connected(hdev, conn, NULL, 0);
 	}
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [v1] Bluetooth: hci_event: Fix not emitting Device Connected event
  2026-12-03 20:50 [PATCH v1] Bluetooth: hci_event: Fix not emitting Device Connected event Luiz Augusto von Dentz
@ 2026-12-04  2:10 ` bluez.test.bot
  0 siblings, 0 replies; 2+ messages in thread
From: bluez.test.bot @ 2026-12-04  2:10 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 2660 bytes --]

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/series/1231101/

---Test result---

Test Summary:
CheckPatch                    FAIL      0.54 seconds
VerifyFixes                   PASS      0.04 seconds
VerifySignedoff               PASS      0.04 seconds
GitLint                       PASS      0.15 seconds
SubjectPrefix                 PASS      0.04 seconds
BuildKernel                   PASS      20.70 seconds
CheckAllWarning               PASS      23.37 seconds
CheckSparse                   WARNING   24.70 seconds
BuildKernel32                 PASS      20.56 seconds
CheckKernelLLVM               PASS      21.79 seconds
TestRunnerSetup               PASS      480.44 seconds
TestRunner_l2cap-tester       PASS      14.12 seconds
TestRunner_iso-tester         PASS      13.64 seconds
TestRunner_bnep-tester        PASS      3.09 seconds
TestRunner_mgmt-tester        PASS      84.88 seconds
TestRunner_rfcomm-tester      PASS      4.35 seconds
TestRunner_sco-tester         PASS      5.35 seconds
TestRunner_ioctl-tester       PASS      4.44 seconds
TestRunner_mesh-tester        PASS      4.37 seconds
TestRunner_smp-tester         PASS      4.25 seconds
TestRunner_userchan-tester    PASS      3.14 seconds
TestRunner_6lowpan-tester     PASS      4.31 seconds
IncrementalBuild              PASS      18.90 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[v1] Bluetooth: hci_event: Fix not emitting Device Connected event
WARNING: Non-standard signature: Assisted-by:
#136: 
Assisted-by: OpenCode:claude-opus-5.5

ERROR: Unrecognized email address: 'OpenCode:claude-opus-5.5'
#136: 
Assisted-by: OpenCode:claude-opus-5.5

total: 1 errors, 1 warnings, 0 checks, 60 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/home/runner/work/bluetooth-next/bluetooth-next/src/patch/15052137.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:
net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):


https://github.com/bluez/bluetooth-next/pull/1284

---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04  2:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 20:50 [PATCH v1] Bluetooth: hci_event: Fix not emitting Device Connected event Luiz Augusto von Dentz
2026-12-04  2:10 ` [v1] " bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox