Bluetooth: mgmt: Fix device_connected sending order
Subsystems (2)
PATCH 1/1 Bluetooth: mgmt: Fix device_connected sending order
From: Johan Hedberg <[email protected]>
The mgmt_ev_device_connected signal must be sent before any event indications happen for sockets associated with the connection. Otherwise e.g. device authorization for the sockets will fail with ENOTCONN as user space things that there is no baseband link.
This patch fixes the issue by ensuring that the device_connected event if sent (if it hasn't been so already) as soon as the first ACL data packet arrives from the remote device.
--- net/bluetooth/hci_core.c | 6 ++++++ net/bluetooth/hci_event.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-)
net/bluetooth/hci_core.c +6 -0
@@ -2785,6 +2785,12 @@ static inline void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)if (conn) {hci_conn_enter_active_mode (conn,BT_POWER_FORCE_ACTIVE_OFF ); +if (test_bit (HCI_MGMT , &hdev->dev_flags) && + !test_and_set_bit (HCI_CONN_MGMT_CONNECTED , &conn->flags)) +mgmt_device_connected (hdev, &conn->dst, conn->type, + conn->dst_type,0 ,NULL ,0 , + conn->dev_class); +/* Send to upper protocol */ l2cap_recv_acldata (conn, skb, flags);return ;
net/bluetooth/hci_event.c +2 -2
@@ -2110,7 +2110,7 @@ static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff goto unlock; } -if (!ev->status) { +if (!ev->status && !test_bit (HCI_CONN_MGMT_CONNECTED , &conn->flags)) {struct hci_cp_remote_name_req cp;memset (&cp,0 ,sizeof (cp));bacpy (&cp.bdaddr, &conn->dst);
@@ -2879,7 +2879,7 @@ static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_bif (conn->state !=BT_CONFIG ) goto unlock; -if (!ev->status) { +if (!ev->status && !test_bit (HCI_CONN_MGMT_CONNECTED , &conn->flags)) {struct hci_cp_remote_name_req cp;memset (&cp,0 ,sizeof (cp));bacpy (&cp.bdaddr, &conn->dst);
Signature · 1 line
1.7.10
PATCH v2 1/1 Bluetooth: mgmt: Fix device_connected sending order
From: Johan Hedberg <[email protected]>
The mgmt_ev_device_connected signal must be sent before any event indications happen for sockets associated with the connection. Otherwise e.g. device authorization for the sockets will fail with ENOTCONN as user space things that there is no baseband link.
This patch fixes the issue by ensuring that the device_connected event if sent (if it hasn't been so already) as soon as the first ACL data packet arrives from the remote device.
---
v2: Fixed missing hdev locking
net/bluetooth/hci_core.c | 8 ++++++++ net/bluetooth/hci_event.c | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-)
net/bluetooth/hci_core.c +8 -0
@@ -2785,6 +2785,14 @@ static inline void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)if (conn) {hci_conn_enter_active_mode (conn,BT_POWER_FORCE_ACTIVE_OFF ); +hci_dev_lock (hdev); +if (test_bit (HCI_MGMT , &hdev->dev_flags) && + !test_and_set_bit (HCI_CONN_MGMT_CONNECTED , &conn->flags)) +mgmt_device_connected (hdev, &conn->dst, conn->type, + conn->dst_type,0 ,NULL ,0 , + conn->dev_class); +hci_dev_unlock (hdev); +/* Send to upper protocol */ l2cap_recv_acldata (conn, skb, flags);return ;
net/bluetooth/hci_event.c +2 -2
@@ -2110,7 +2110,7 @@ static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff goto unlock; } -if (!ev->status) { +if (!ev->status && !test_bit (HCI_CONN_MGMT_CONNECTED , &conn->flags)) {struct hci_cp_remote_name_req cp;memset (&cp,0 ,sizeof (cp));bacpy (&cp.bdaddr, &conn->dst);
@@ -2879,7 +2879,7 @@ static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_bif (conn->state !=BT_CONFIG ) goto unlock; -if (!ev->status) { +if (!ev->status && !test_bit (HCI_CONN_MGMT_CONNECTED , &conn->flags)) {struct hci_cp_remote_name_req cp;memset (&cp,0 ,sizeof (cp));bacpy (&cp.bdaddr, &conn->dst);
Signature · 1 line
1.7.10
Hi Johan,
Quoted 10 lines · Johan Hedberg
From: Johan Hedberg <[email protected]>
The
mgmt_ev_device_connectedsignal must be sent before any event indications happen for sockets associated with the connection. Otherwise e.g. device authorization for the sockets will fail with ENOTCONN as user space things that there is no baseband link.This patch fixes the issue by ensuring that the
device_connectedevent if sent (if it hasn't been so already) as soon as the first ACL data packet arrives from the remote device.
This patch fixes the ENOTCONN issue for me. Let's see if Marcel or someone else wants comment on it before we go ahead and apply it.
Quoted 1 line
Gustavo
Hi Johan,
Quoted 9 lines
The
mgmt_ev_device_connectedsignal must be sent before any event indications happen for sockets associated with the connection. Otherwise e.g. device authorization for the sockets will fail with ENOTCONN as user space things that there is no baseband link.This patch fixes the issue by ensuring that the
device_connectedevent if sent (if it hasn't been so already) as soon as the first ACL data packet arrives from the remote device.
Quoted 7 lines
Signed-off-by Johan Hedberg <[email protected]>---
v2: Fixed missing hdev lockingnet/bluetooth/hci_core.c | 8 ++++++++ net/bluetooth/hci_event.c | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-)
Regards
Marcel
Hi Marcel,
Quoted 13 lines · Marcel Holtmann
Quoted 13 lines
The
mgmt_ev_device_connectedsignal must be sent before any event indications happen for sockets associated with the connection. Otherwise e.g. device authorization for the sockets will fail with ENOTCONN as user space things that there is no baseband link.This patch fixes the issue by ensuring that the
device_connectedevent if sent (if it hasn't been so already) as soon as the first ACL data packet arrives from the remote device.Signed-off-by Johan Hedberg <[email protected]>---
v2: Fixed missing hdev locking
Quoted 5 lines
Quoted 3 lines
net/bluetooth/hci_core.c | 8 ++++++++ net/bluetooth/hci_event.c | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-)Acked-by Marcel Holtmann <[email protected]>
Thanks. The patch is now in bluetooth.git.
Johan