]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
Bluetooth: hci_core: Fix sending MGMT_EV_CONNECT_FAILED
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 30 Aug 2024 21:29:27 +0000 (17:29 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 4 Oct 2024 14:32:28 +0000 (16:32 +0200)
[ Upstream commit d47da6bd4cfa982fe903f33423b9e2ec541e9496 ]

If HCI_CONN_MGMT_CONNECTED has been set then the event shall be
HCI_CONN_MGMT_DISCONNECTED.

Fixes: b644ba336997 ("Bluetooth: Update device_connected and device_found events to latest API")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/net/bluetooth/hci_core.h
net/bluetooth/hci_conn.c
net/bluetooth/mgmt.c

index ecb6824e9add835f7857dba043499208b65cc4c3..9cfd1ce0fd36c4e4f8d5b0a5825b1ba4806a85a3 100644 (file)
@@ -2258,8 +2258,8 @@ void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
                              bool mgmt_connected);
 void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
                            u8 link_type, u8 addr_type, u8 status);
-void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
-                        u8 addr_type, u8 status);
+void mgmt_connect_failed(struct hci_dev *hdev, struct hci_conn *conn,
+                        u8 status);
 void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
 void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
                                  u8 status);
index 3c74d171085deb2cf4b8f96552a2d4fc595afdc4..bfa773730f3bd75054e422f5e0cd39a66f557e93 100644 (file)
@@ -107,8 +107,7 @@ void hci_connect_le_scan_cleanup(struct hci_conn *conn, u8 status)
         * where a timeout + cancel does indicate an actual failure.
         */
        if (status && status != HCI_ERROR_UNKNOWN_CONN_ID)
-               mgmt_connect_failed(hdev, &conn->dst, conn->type,
-                                   conn->dst_type, status);
+               mgmt_connect_failed(hdev, conn, status);
 
        /* The connection attempt was doing scan for new RPA, and is
         * in scan phase. If params are not associated with any other
@@ -1251,8 +1250,7 @@ void hci_conn_failed(struct hci_conn *conn, u8 status)
                hci_le_conn_failed(conn, status);
                break;
        case ACL_LINK:
-               mgmt_connect_failed(hdev, &conn->dst, conn->type,
-                                   conn->dst_type, status);
+               mgmt_connect_failed(hdev, conn, status);
                break;
        }
 
index ba28907afb3fa65746b77f6cd29f85cfcc57c861..c383eb44d516bc269c89489c52085b4733fa8aef 100644 (file)
@@ -9734,13 +9734,18 @@ void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
        mgmt_pending_remove(cmd);
 }
 
-void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
-                        u8 addr_type, u8 status)
+void mgmt_connect_failed(struct hci_dev *hdev, struct hci_conn *conn, u8 status)
 {
        struct mgmt_ev_connect_failed ev;
 
-       bacpy(&ev.addr.bdaddr, bdaddr);
-       ev.addr.type = link_to_bdaddr(link_type, addr_type);
+       if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) {
+               mgmt_device_disconnected(hdev, &conn->dst, conn->type,
+                                        conn->dst_type, status, true);
+               return;
+       }
+
+       bacpy(&ev.addr.bdaddr, &conn->dst);
+       ev.addr.type = link_to_bdaddr(conn->type, conn->dst_type);
        ev.status = mgmt_status(status);
 
        mgmt_event(MGMT_EV_CONNECT_FAILED, hdev, &ev, sizeof(ev), NULL);