Skip to contentSkip to conversation

A few more cleanups for l2cap_chan based SMP

PATCH In review [email protected] 2 participants 5 messages Aug 8, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover A few more cleanups for l2cap_chan based SMP

Hi,

Here are a few more cleanups/fixes in preparation for converting SMP to use l2cap_chan.

Johan

----------------------------------------------------------------
Johan Hedberg (3):
Bluetooth: Call L2CAP teardown callback before clearing chan->conn
Bluetooth: Call l2cap_le_conn_ready after notifying channels
Bluetooth: Fix using HCI_CONN_LE_SMP_PEND to check for SMP context

 net/bluetooth/l2cap_core.c | 10 +++++-----
 net/bluetooth/smp.c        |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)
#1 lore raw

PATCH 1/3 Bluetooth: Call L2CAP teardown callback before clearing chan->conn

From: Johan Hedberg <[email protected]>

L2CAP channel implementations may want to still access the chan->conn pointer. This will particularly be the case for SMP that will want to clear a reference to the SMP channel in the l2cap_conn structure. The only user of the teardown callback so far is l2cap_sock.c and for the code there it makes no difference whether the callback is called before or after clearing the chan->conn pointer.

---
 net/bluetooth/l2cap_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/bluetooth/l2cap_core.c +2 -2
index 344a29c53227..c6419f40cfba 100644
@@ -566,6 +566,8 @@ void l2cap_chan_del(struct l2cap_chan *chan, int err)
 
 	BT_DBG("chan %p, conn %p, err %d", chan, conn, err);
 
+	chan->ops->teardown(chan, err);
+
 	if (conn) {
 		struct amp_mgr *mgr = conn->hcon->amp_mgr;
 		/* Delete from channel list */
@@ -589,8 +591,6 @@ void l2cap_chan_del(struct l2cap_chan *chan, int err)
 		amp_disconnect_logical_link(hs_hchan);
 	}
 
-	chan->ops->teardown(chan, err);
-
 	if (test_bit(CONF_NOT_COMPLETE, &chan->conf_state))
 		return;
 
Signature · 1 line
1.9.3
#2 lore raw

PATCH 2/3 Bluetooth: Call l2cap_le_conn_ready after notifying channels

In reply to [email protected]

From: Johan Hedberg <[email protected]>

For most cases it makes no difference whether l2cap_le_conn_ready() is called before or after calling the channel ready() callbacks, however for upcoming SMP code we need this as the ready() callback initializes certain structures that a call to smp_conn_security() from l2cap_le_conn_ready() depends on. Therefore, move the call to l2cap_le_conn_ready() after iterating through and notifying channels.

---
 net/bluetooth/l2cap_core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/bluetooth/l2cap_core.c +3 -3
index c6419f40cfba..8acfe6f57b5e 100644
@@ -1464,9 +1464,6 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
 
 	BT_DBG("conn %p", conn);
 
-	if (hcon->type == LE_LINK)
-		l2cap_le_conn_ready(conn);
-
 	mutex_lock(&conn->chan_lock);
 
 	list_for_each_entry(chan, &conn->chan_l, list) {
@@ -1492,6 +1489,9 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
 
 	mutex_unlock(&conn->chan_lock);
 
+	if (hcon->type == LE_LINK)
+		l2cap_le_conn_ready(conn);
+
 	queue_work(hcon->hdev->workqueue, &conn->pending_rx_work);
 }
 
Signature · 1 line
1.9.3
#3 lore raw

PATCH 3/3 Bluetooth: Fix using HCI_CONN_LE_SMP_PEND to check for SMP context

In reply to [email protected]

From: Johan Hedberg <[email protected]>

The code is consistently using the HCI_CONN_LE_SMP_PEND flag check for the existence of the SMP context, with the exception of this one place in smp_sig_channel(). This patch converts the place to use the flag just like all other instances.

---
 net/bluetooth/smp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/smp.c +1 -1
index 40db728f044b..33016ec9b247 100644
@@ -1206,7 +1206,7 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
 	 * returns an error).
 	 */
 	if (code != SMP_CMD_PAIRING_REQ && code != SMP_CMD_SECURITY_REQ &&
-	    !conn->smp_chan) {
+	    !test_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags)) {
 		BT_ERR("Unexpected SMP command 0x%02x. Disconnecting.", code);
 		kfree_skb(skb);
 		return -EOPNOTSUPP;
Signature · 1 line
1.9.3
maintainer
#4 lore raw
In reply to [email protected]

Hi Johan,

Quoted 11 lines

Here are a few more cleanups/fixes in preparation for converting SMP to use l2cap_chan.

Johan

----------------------------------------------------------------
Johan Hedberg (3):
Bluetooth: Call L2CAP teardown callback before clearing chan->conn
Bluetooth: Call l2cap_le_conn_ready after notifying channels
Bluetooth: Fix using HCI_CONN_LE_SMP_PEND to check for SMP context

Quoted 3 lines

net/bluetooth/l2cap_core.c | 10 +++++-----
net/bluetooth/smp.c | 2 +-

2 files changed, 6 insertions(+), 6 deletions(-)

all 3 patches have been applied to bluetooth-next tree.

Regards

Marcel