Skip to contentSkip to conversation

Bluetooth: MGMT: Fix not generating command complete for MGMT_OP_DISCONNECT

PATCH New Luiz Augusto von Dentz 1 participant 1 message Aug 22, 2024

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 Bluetooth: MGMT: Fix not generating command complete for MGMT_OP_DISCONNECT

From: Luiz Augusto von Dentz <[email protected]>

MGMT_OP_DISCONNECT can be called while mgmt_device_connected has not been called yet, which will cause the connection procedure to be aborted, so mgmt_device_disconnected shall still respond with command complete to MGMT_OP_DISCONNECT and just not emit MGMT_EV_DEVICE_DISCONNECTED since MGMT_EV_DEVICE_CONNECTED was never sent.

Fixes 12d4a3b2ccb3 ("Bluetooth: Move check for MGMT_CONNECTED flag into mgmt.c")
---
 net/bluetooth/mgmt.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
net/bluetooth/mgmt.c +6 -4
index 25979f4283a6..fdfe9675535d 100644
@@ -9738,9 +9738,6 @@ void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
 	struct mgmt_ev_device_disconnected ev;
 	struct sock *sk = NULL;
 
-	if (!mgmt_connected)
-		return;
-
 	if (link_type != ACL_LINK && link_type != LE_LINK)
 		return;
 
@@ -9754,7 +9751,12 @@ void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
 	if (hdev->suspended)
 		ev.reason = MGMT_DEV_DISCONN_LOCAL_HOST_SUSPEND;
 
-	mgmt_event(MGMT_EV_DEVICE_DISCONNECTED, hdev, &ev, sizeof(ev), sk);
+	/* Only report MGMT_EV_DEVICE_DISCONNECTED if device is considered
+	 * connected.
+	 */
+	if (mgmt_connected)
+		mgmt_event(MGMT_EV_DEVICE_DISCONNECTED, hdev, &ev, sizeof(ev),
+			   sk);
 
 	if (sk)
 		sock_put(sk);
Signature · 1 line
2.46.0