linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: mgmt: Fix device_connected sending order
@ 2012-05-04 10:37 Johan Hedberg
  2012-05-04 10:45 ` [PATCH v2] " Johan Hedberg
  0 siblings, 1 reply; 5+ messages in thread
From: Johan Hedberg @ 2012-05-04 10:37 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

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.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/hci_core.c  |    6 ++++++
 net/bluetooth/hci_event.c |    4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index a7607e4..0a69272 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -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;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index d986e7b..1d686e1 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -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_b
 	if (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);
-- 
1.7.10


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

* [PATCH v2] Bluetooth: mgmt: Fix device_connected sending order
  2012-05-04 10:37 [PATCH] Bluetooth: mgmt: Fix device_connected sending order Johan Hedberg
@ 2012-05-04 10:45 ` Johan Hedberg
  2012-05-04 19:51   ` Gustavo Padovan
  2012-05-06 16:16   ` Marcel Holtmann
  0 siblings, 2 replies; 5+ messages in thread
From: Johan Hedberg @ 2012-05-04 10:45 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

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.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
v2: Fixed missing hdev locking

 net/bluetooth/hci_core.c  |    8 ++++++++
 net/bluetooth/hci_event.c |    4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index a7607e4..b5bab83 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -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;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index d986e7b..1d686e1 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -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_b
 	if (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);
-- 
1.7.10


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

* Re: [PATCH v2] Bluetooth: mgmt: Fix device_connected sending order
  2012-05-04 10:45 ` [PATCH v2] " Johan Hedberg
@ 2012-05-04 19:51   ` Gustavo Padovan
  2012-05-06 16:16   ` Marcel Holtmann
  1 sibling, 0 replies; 5+ messages in thread
From: Gustavo Padovan @ 2012-05-04 19:51 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

* Johan Hedberg <johan.hedberg@gmail.com> [2012-05-04 13:45:29 +0300]:

> From: Johan Hedberg <johan.hedberg@intel.com>
> 
> 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.

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.
> 
	Gustavo

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

* Re: [PATCH v2] Bluetooth: mgmt: Fix device_connected sending order
  2012-05-04 10:45 ` [PATCH v2] " Johan Hedberg
  2012-05-04 19:51   ` Gustavo Padovan
@ 2012-05-06 16:16   ` Marcel Holtmann
  2012-05-07 17:57     ` Johan Hedberg
  1 sibling, 1 reply; 5+ messages in thread
From: Marcel Holtmann @ 2012-05-06 16:16 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

> 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.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> v2: Fixed missing hdev locking
> 
>  net/bluetooth/hci_core.c  |    8 ++++++++
>  net/bluetooth/hci_event.c |    4 ++--
>  2 files changed, 10 insertions(+), 2 deletions(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel



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

* Re: [PATCH v2] Bluetooth: mgmt: Fix device_connected sending order
  2012-05-06 16:16   ` Marcel Holtmann
@ 2012-05-07 17:57     ` Johan Hedberg
  0 siblings, 0 replies; 5+ messages in thread
From: Johan Hedberg @ 2012-05-07 17:57 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth

Hi Marcel,

On Sun, May 06, 2012, Marcel Holtmann wrote:
> > 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.
> > 
> > Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> > ---
> > v2: Fixed missing hdev locking
> > 
> >  net/bluetooth/hci_core.c  |    8 ++++++++
> >  net/bluetooth/hci_event.c |    4 ++--
> >  2 files changed, 10 insertions(+), 2 deletions(-)
> 
> Acked-by: Marcel Holtmann <marcel@holtmann.org>

Thanks. The patch is now in bluetooth.git.

Johan

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

end of thread, other threads:[~2012-05-07 17:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-04 10:37 [PATCH] Bluetooth: mgmt: Fix device_connected sending order Johan Hedberg
2012-05-04 10:45 ` [PATCH v2] " Johan Hedberg
2012-05-04 19:51   ` Gustavo Padovan
2012-05-06 16:16   ` Marcel Holtmann
2012-05-07 17:57     ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).