linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC 1/5] Bluetooth: Fix using locked state_change for A2MP chan
@ 2012-12-07 12:59 Andrei Emeltchenko
  2012-12-07 12:59 ` [RFC 2/5] Bluetooth: AMP: Send A2MP Create Phylink Rsp after Assoc write Andrei Emeltchenko
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Andrei Emeltchenko @ 2012-12-07 12:59 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

A2MP channel do not have sk associated so use unlocked version
of state_change. chan is already locked.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 net/bluetooth/l2cap_core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 2c78208..d4a44dc 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1196,7 +1196,7 @@ static void l2cap_send_disconn_req(struct l2cap_chan *chan, int err)
 	}
 
 	if (chan->chan_type == L2CAP_CHAN_CONN_FIX_A2MP) {
-		l2cap_state_change(chan, BT_DISCONN);
+		__l2cap_state_change(chan, BT_DISCONN);
 		return;
 	}
 
-- 
1.7.10.4


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

* [RFC 2/5] Bluetooth: AMP: Send A2MP Create Phylink Rsp after Assoc write
  2012-12-07 12:59 [RFC 1/5] Bluetooth: Fix using locked state_change for A2MP chan Andrei Emeltchenko
@ 2012-12-07 12:59 ` Andrei Emeltchenko
  2012-12-07 12:59 ` [RFC 3/5] Bluetooth: AMP: Clean up logical link create / accept Andrei Emeltchenko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Andrei Emeltchenko @ 2012-12-07 12:59 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Postpone sending A2MP Create Phylink Response till we got successful
HCI Command Complete after HCI Write Remote AMP Assoc.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 include/net/bluetooth/a2mp.h |    2 ++
 net/bluetooth/a2mp.c         |   38 ++++++++++++++++++++++++++++++++++++--
 net/bluetooth/amp.c          |    6 +++++-
 3 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/include/net/bluetooth/a2mp.h b/include/net/bluetooth/a2mp.h
index 42f2176..8b39327 100644
--- a/include/net/bluetooth/a2mp.h
+++ b/include/net/bluetooth/a2mp.h
@@ -23,6 +23,7 @@ enum amp_mgr_state {
 	READ_LOC_AMP_INFO,
 	READ_LOC_AMP_ASSOC,
 	READ_LOC_AMP_ASSOC_FINAL,
+	WRITE_REMOTE_AMP_ASSOC,
 };
 
 struct amp_mgr {
@@ -144,5 +145,6 @@ void a2mp_discover_amp(struct l2cap_chan *chan);
 void a2mp_send_getinfo_rsp(struct hci_dev *hdev);
 void a2mp_send_getampassoc_rsp(struct hci_dev *hdev, u8 status);
 void a2mp_send_create_phy_link_req(struct hci_dev *hdev, u8 status);
+void a2mp_send_create_phy_link_rsp(struct hci_dev *hdev, u8 status);
 
 #endif /* __A2MP_H */
diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c
index 2f67d5e..c960c20 100644
--- a/net/bluetooth/a2mp.c
+++ b/net/bluetooth/a2mp.c
@@ -499,8 +499,16 @@ send_rsp:
 	if (hdev)
 		hci_dev_put(hdev);
 
-	a2mp_send(mgr, A2MP_CREATEPHYSLINK_RSP, hdr->ident, sizeof(rsp),
-		  &rsp);
+	/* Reply error now and succes after HCI Write Remote AMP Assoc
+	   command complete with success status
+	 */
+	if (rsp.status != A2MP_STATUS_SUCCESS) {
+		a2mp_send(mgr, A2MP_CREATEPHYSLINK_RSP, hdr->ident,
+			  sizeof(rsp), &rsp);
+	} else {
+		mgr->state = WRITE_REMOTE_AMP_ASSOC;
+		mgr->ident = hdr->ident;
+	}
 
 	skb_pull(skb, le16_to_cpu(hdr->len));
 	return 0;
@@ -949,6 +957,32 @@ clean:
 	kfree(req);
 }
 
+void a2mp_send_create_phy_link_rsp(struct hci_dev *hdev, u8 status)
+{
+	struct amp_mgr *mgr;
+	struct a2mp_physlink_rsp rsp;
+	struct hci_conn *hs_hcon;
+
+	mgr = amp_mgr_lookup_by_state(WRITE_REMOTE_AMP_ASSOC);
+	if (!mgr)
+		return;
+
+	hs_hcon = hci_conn_hash_lookup_state(hdev, AMP_LINK, BT_CONNECT);
+	if (!hs_hcon) {
+		rsp.status = A2MP_STATUS_UNABLE_START_LINK_CREATION;
+	} else {
+		rsp.remote_id = hs_hcon->remote_id;
+		rsp.status = A2MP_STATUS_SUCCESS;
+	}
+
+	BT_DBG("%s mgr %p hs_hcon %p status %u", hdev->name, mgr, hs_hcon,
+	       status);
+
+	rsp.local_id = hdev->id;
+	a2mp_send(mgr, A2MP_CREATEPHYSLINK_RSP, mgr->ident, sizeof(rsp), &rsp);
+	amp_mgr_put(mgr);
+}
+
 void a2mp_discover_amp(struct l2cap_chan *chan)
 {
 	struct l2cap_conn *conn = chan->conn;
diff --git a/net/bluetooth/amp.c b/net/bluetooth/amp.c
index 1b0d92c..88720e8 100644
--- a/net/bluetooth/amp.c
+++ b/net/bluetooth/amp.c
@@ -317,7 +317,11 @@ void amp_write_rem_assoc_continue(struct hci_dev *hdev, u8 handle)
 	if (!hcon)
 		return;
 
-	amp_write_rem_assoc_frag(hdev, hcon);
+	/* Send A2MP create phylink rsp whan all fragments are
+	   written
+	 */
+	if (amp_write_rem_assoc_frag(hdev, hcon))
+		a2mp_send_create_phy_link_rsp(hdev, 0);
 }
 
 void amp_write_remote_assoc(struct hci_dev *hdev, u8 handle)
-- 
1.7.10.4


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

* [RFC 3/5] Bluetooth: AMP: Clean up logical link create / accept
  2012-12-07 12:59 [RFC 1/5] Bluetooth: Fix using locked state_change for A2MP chan Andrei Emeltchenko
  2012-12-07 12:59 ` [RFC 2/5] Bluetooth: AMP: Send A2MP Create Phylink Rsp after Assoc write Andrei Emeltchenko
@ 2012-12-07 12:59 ` Andrei Emeltchenko
  2012-12-07 12:59 ` [RFC 4/5] Bluetooth: AMP: Remove dead code Andrei Emeltchenko
  2012-12-07 12:59 ` [RFC 5/5] Bluetooth: AMP: Use set_bit / test_bit for amp_mgr state Andrei Emeltchenko
  3 siblings, 0 replies; 6+ messages in thread
From: Andrei Emeltchenko @ 2012-12-07 12:59 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Use chan->hs_hcon instead of lookup by dst address.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 net/bluetooth/amp.c |   17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/net/bluetooth/amp.c b/net/bluetooth/amp.c
index 88720e8..f55d3f2 100644
--- a/net/bluetooth/amp.c
+++ b/net/bluetooth/amp.c
@@ -407,26 +407,20 @@ void amp_physical_cfm(struct hci_conn *bredr_hcon, struct hci_conn *hs_hcon)
 
 void amp_create_logical_link(struct l2cap_chan *chan)
 {
+	struct hci_conn *hs_hcon = chan->hs_hcon;
 	struct hci_cp_create_accept_logical_link cp;
-	struct hci_conn *hcon;
 	struct hci_dev *hdev;
 
-	BT_DBG("chan %p", chan);
+	BT_DBG("chan %p hs_hcon %p dst %pMR", chan, hs_hcon, chan->conn->dst);
 
-	if (!chan->hs_hcon)
+	if (!hs_hcon)
 		return;
 
 	hdev = hci_dev_hold(chan->hs_hcon->hdev);
 	if (!hdev)
 		return;
 
-	BT_DBG("chan %p dst %pMR", chan, chan->conn->dst);
-
-	hcon = hci_conn_hash_lookup_ba(hdev, AMP_LINK, chan->conn->dst);
-	if (!hcon)
-		goto done;
-
-	cp.phy_handle = hcon->handle;
+	cp.phy_handle = hs_hcon->handle;
 
 	cp.tx_flow_spec.id = chan->local_id;
 	cp.tx_flow_spec.stype = chan->local_stype;
@@ -442,14 +436,13 @@ void amp_create_logical_link(struct l2cap_chan *chan)
 	cp.rx_flow_spec.acc_lat = cpu_to_le32(chan->remote_acc_lat);
 	cp.rx_flow_spec.flush_to = cpu_to_le32(chan->remote_flush_to);
 
-	if (hcon->out)
+	if (hs_hcon->out)
 		hci_send_cmd(hdev, HCI_OP_CREATE_LOGICAL_LINK, sizeof(cp),
 			     &cp);
 	else
 		hci_send_cmd(hdev, HCI_OP_ACCEPT_LOGICAL_LINK, sizeof(cp),
 			     &cp);
 
-done:
 	hci_dev_put(hdev);
 }
 
-- 
1.7.10.4


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

* [RFC 4/5] Bluetooth: AMP: Remove dead code
  2012-12-07 12:59 [RFC 1/5] Bluetooth: Fix using locked state_change for A2MP chan Andrei Emeltchenko
  2012-12-07 12:59 ` [RFC 2/5] Bluetooth: AMP: Send A2MP Create Phylink Rsp after Assoc write Andrei Emeltchenko
  2012-12-07 12:59 ` [RFC 3/5] Bluetooth: AMP: Clean up logical link create / accept Andrei Emeltchenko
@ 2012-12-07 12:59 ` Andrei Emeltchenko
  2012-12-07 12:59 ` [RFC 5/5] Bluetooth: AMP: Use set_bit / test_bit for amp_mgr state Andrei Emeltchenko
  3 siblings, 0 replies; 6+ messages in thread
From: Andrei Emeltchenko @ 2012-12-07 12:59 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Remove code which cannot execute. l2cap_conn_add for AMP_LINK
might only be invoked when receiving data in l2cap_recv_acldata.
But this case is checked in the first statement there.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 net/bluetooth/l2cap_core.c |    5 -----
 1 file changed, 5 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index d4a44dc..4976d12 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1527,17 +1527,12 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon, u8 status)
 	BT_DBG("hcon %p conn %p hchan %p", hcon, conn, hchan);
 
 	switch (hcon->type) {
-	case AMP_LINK:
-		conn->mtu = hcon->hdev->block_mtu;
-		break;
-
 	case LE_LINK:
 		if (hcon->hdev->le_mtu) {
 			conn->mtu = hcon->hdev->le_mtu;
 			break;
 		}
 		/* fall through */
-
 	default:
 		conn->mtu = hcon->hdev->acl_mtu;
 		break;
-- 
1.7.10.4


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

* [RFC 5/5] Bluetooth: AMP: Use set_bit / test_bit for amp_mgr state
  2012-12-07 12:59 [RFC 1/5] Bluetooth: Fix using locked state_change for A2MP chan Andrei Emeltchenko
                   ` (2 preceding siblings ...)
  2012-12-07 12:59 ` [RFC 4/5] Bluetooth: AMP: Remove dead code Andrei Emeltchenko
@ 2012-12-07 12:59 ` Andrei Emeltchenko
  2012-12-21  1:38   ` Gustavo Padovan
  3 siblings, 1 reply; 6+ messages in thread
From: Andrei Emeltchenko @ 2012-12-07 12:59 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Using bit operations solves problems with multiple requests
and clearing state.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 include/net/bluetooth/a2mp.h |    2 +-
 net/bluetooth/a2mp.c         |    6 +++---
 net/bluetooth/amp.c          |    4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/net/bluetooth/a2mp.h b/include/net/bluetooth/a2mp.h
index 8b39327..487b54c 100644
--- a/include/net/bluetooth/a2mp.h
+++ b/include/net/bluetooth/a2mp.h
@@ -34,7 +34,7 @@ struct amp_mgr {
 	struct kref		kref;
 	__u8			ident;
 	__u8			handle;
-	enum amp_mgr_state	state;
+	unsigned long		state;
 	unsigned long		flags;
 
 	struct list_head	amp_ctrls;
diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c
index c960c20..50d2771 100644
--- a/net/bluetooth/a2mp.c
+++ b/net/bluetooth/a2mp.c
@@ -290,7 +290,7 @@ static int a2mp_getinfo_req(struct amp_mgr *mgr, struct sk_buff *skb,
 		goto done;
 	}
 
-	mgr->state = READ_LOC_AMP_INFO;
+	set_bit(READ_LOC_AMP_INFO, &mgr->state);
 	hci_send_cmd(hdev, HCI_OP_READ_LOCAL_AMP_INFO, 0, NULL);
 
 done:
@@ -506,7 +506,7 @@ send_rsp:
 		a2mp_send(mgr, A2MP_CREATEPHYSLINK_RSP, hdr->ident,
 			  sizeof(rsp), &rsp);
 	} else {
-		mgr->state = WRITE_REMOTE_AMP_ASSOC;
+		set_bit(WRITE_REMOTE_AMP_ASSOC, &mgr->state);
 		mgr->ident = hdr->ident;
 	}
 
@@ -848,7 +848,7 @@ struct amp_mgr *amp_mgr_lookup_by_state(u8 state)
 
 	mutex_lock(&amp_mgr_list_lock);
 	list_for_each_entry(mgr, &amp_mgr_list, list) {
-		if (mgr->state == state) {
+		if (test_and_clear_bit(state, &mgr->state)) {
 			amp_mgr_get(mgr);
 			mutex_unlock(&amp_mgr_list_lock);
 			return mgr;
diff --git a/net/bluetooth/amp.c b/net/bluetooth/amp.c
index f55d3f2..1bbb59d 100644
--- a/net/bluetooth/amp.c
+++ b/net/bluetooth/amp.c
@@ -236,7 +236,7 @@ void amp_read_loc_assoc(struct hci_dev *hdev, struct amp_mgr *mgr)
 
 	cp.max_len = cpu_to_le16(hdev->amp_assoc_size);
 
-	mgr->state = READ_LOC_AMP_ASSOC;
+	set_bit(READ_LOC_AMP_ASSOC, &mgr->state);
 	hci_send_cmd(hdev, HCI_OP_READ_LOCAL_AMP_ASSOC, sizeof(cp), &cp);
 }
 
@@ -250,7 +250,7 @@ void amp_read_loc_assoc_final_data(struct hci_dev *hdev,
 	cp.len_so_far = cpu_to_le16(0);
 	cp.max_len = cpu_to_le16(hdev->amp_assoc_size);
 
-	mgr->state = READ_LOC_AMP_ASSOC_FINAL;
+	set_bit(READ_LOC_AMP_ASSOC_FINAL, &mgr->state);
 
 	/* Read Local AMP Assoc final link information data */
 	hci_send_cmd(hdev, HCI_OP_READ_LOCAL_AMP_ASSOC, sizeof(cp), &cp);
-- 
1.7.10.4


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

* Re: [RFC 5/5] Bluetooth: AMP: Use set_bit / test_bit for amp_mgr state
  2012-12-07 12:59 ` [RFC 5/5] Bluetooth: AMP: Use set_bit / test_bit for amp_mgr state Andrei Emeltchenko
@ 2012-12-21  1:38   ` Gustavo Padovan
  0 siblings, 0 replies; 6+ messages in thread
From: Gustavo Padovan @ 2012-12-21  1:38 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth

Hi Andrei,

* Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com> [2012-12-07 14:59:08 +0200]:

> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> 
> Using bit operations solves problems with multiple requests
> and clearing state.
> 
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> ---
>  include/net/bluetooth/a2mp.h |    2 +-
>  net/bluetooth/a2mp.c         |    6 +++---
>  net/bluetooth/amp.c          |    4 ++--
>  3 files changed, 6 insertions(+), 6 deletions(-)

Patch 2 to 5 have been applied to bluetooth-next. Thanks.

	Gustavo

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

end of thread, other threads:[~2012-12-21  1:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-07 12:59 [RFC 1/5] Bluetooth: Fix using locked state_change for A2MP chan Andrei Emeltchenko
2012-12-07 12:59 ` [RFC 2/5] Bluetooth: AMP: Send A2MP Create Phylink Rsp after Assoc write Andrei Emeltchenko
2012-12-07 12:59 ` [RFC 3/5] Bluetooth: AMP: Clean up logical link create / accept Andrei Emeltchenko
2012-12-07 12:59 ` [RFC 4/5] Bluetooth: AMP: Remove dead code Andrei Emeltchenko
2012-12-07 12:59 ` [RFC 5/5] Bluetooth: AMP: Use set_bit / test_bit for amp_mgr state Andrei Emeltchenko
2012-12-21  1:38   ` Gustavo Padovan

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