Skip to contentSkip to conversation

Move SMP encryption to a workqueue

PATCH In review Vinicius Costa Gomes 2 participants 4 messages Sep 5, 2011 – Sep 13, 2011

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

v2 cover Move SMP encryption to a workqueue

Hi,

Changes from last version:

- use the hci_dev workqueue for SMP crypto work;
- move declaration of smp_chan to smp.h

Cheers,
--

Vinicius Costa Gomes (2):
Bluetooth: Move SMP fields to a separate structure
Bluetooth: Move SMP crypto functions to a workqueue

 include/net/bluetooth/hci_core.h |    2 -
 include/net/bluetooth/l2cap.h    |    8 +-
 include/net/bluetooth/smp.h      |   17 ++
 net/bluetooth/hci_core.c         |    8 -
 net/bluetooth/l2cap_core.c       |    2 +-
 net/bluetooth/smp.c              |  339 +++++++++++++++++++++++---------------
 6 files changed, 226 insertions(+), 150 deletions(-)

--
1.7.6.1

#1 lore raw

PATCH v2 1/2 Bluetooth: Move SMP fields to a separate structure

The objective is to make the core to have as little as possible information about SMP procedures and logic. Now, all the SMP specific information is hidden from the core.

---
 include/net/bluetooth/hci_core.h |    2 -
 include/net/bluetooth/l2cap.h    |    8 +---
 include/net/bluetooth/smp.h      |   10 ++++
 net/bluetooth/hci_core.c         |    8 ---
 net/bluetooth/smp.c              |  108 +++++++++++++++++++-------------------
 5 files changed, 65 insertions(+), 71 deletions(-)
include/net/bluetooth/hci_core.h +0 -2
index 9ffd27e..5b92442 100644
@@ -195,8 +195,6 @@ struct hci_dev {
 
 	__u16			init_last_cmd;
 
-	struct crypto_blkcipher	*tfm;
-
 	struct inquiry_cache	inq_cache;
 	struct hci_conn_hash	conn_hash;
 	struct list_head	blacklist;
include/net/bluetooth/l2cap.h +1 -7
index 6fa1140..ab90ae0 100644
@@ -409,14 +409,8 @@ struct l2cap_conn {
 
 	__u8		disc_reason;
 
-	__u8		preq[7]; /* SMP Pairing Request */
-	__u8		prsp[7]; /* SMP Pairing Response */
-	__u8		prnd[16]; /* SMP Pairing Random */
-	__u8		pcnf[16]; /* SMP Pairing Confirm */
-	__u8		tk[16]; /* SMP Temporary Key */
-	__u8		smp_key_size;
-
 	struct timer_list security_timer;
+	struct smp_chan *smp_chan;
 
 	struct list_head chan_l;
 	rwlock_t	chan_lock;
include/net/bluetooth/smp.h +10 -0
index 46c4576..a9ba72c 100644
@@ -115,6 +115,16 @@ struct smp_cmd_security_req {
 #define SMP_MIN_ENC_KEY_SIZE		7
 #define SMP_MAX_ENC_KEY_SIZE		16
 
+struct smp_chan {
+	u8		preq[7]; /* SMP Pairing Request */
+	u8		prsp[7]; /* SMP Pairing Response */
+	u8		prnd[16]; /* SMP Pairing Random */
+	u8		pcnf[16]; /* SMP Pairing Confirm */
+	u8		tk[16]; /* SMP Temporary Key */
+	u8		smp_key_size;
+	struct crypto_blkcipher	*tfm;
+};
+
 /* SMP Commands */
 int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level);
 int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb);
net/bluetooth/hci_core.c +0 -8
index 446bfdb..0f1d2d8 100644
@@ -1507,11 +1507,6 @@ int hci_register_dev(struct hci_dev *hdev)
 	if (!hdev->workqueue)
 		goto nomem;
 
-	hdev->tfm = crypto_alloc_blkcipher("ecb(aes)", 0, CRYPTO_ALG_ASYNC);
-	if (IS_ERR(hdev->tfm))
-		BT_INFO("Failed to load transform for ecb(aes): %ld",
-							PTR_ERR(hdev->tfm));
-
 	hci_register_sysfs(hdev);
 
 	hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev,
@@ -1560,9 +1555,6 @@ int hci_unregister_dev(struct hci_dev *hdev)
 					!test_bit(HCI_SETUP, &hdev->flags))
 		mgmt_index_removed(hdev->id);
 
-	if (!IS_ERR(hdev->tfm))
-		crypto_free_blkcipher(hdev->tfm);
-
 	hci_notify(hdev, HCI_DEV_UNREG);
 
 	if (hdev->rfkill) {
net/bluetooth/smp.c +54 -54

305 lines not on this page · raw message

Signature · 1 line
1.7.6.1
#2 lore raw

PATCH v2 2/2 Bluetooth: Move SMP crypto functions to a workqueue

In reply to Vinicius Costa Gomes

The function crypto_blkcipher_setkey() called by smp_e() can sleep, so all the crypto work has to be moved to hci_dev workqueue.

---
 include/net/bluetooth/smp.h |    9 ++-
 net/bluetooth/l2cap_core.c  |    2 +-
 net/bluetooth/smp.c         |  277 +++++++++++++++++++++++++++----------------
 3 files changed, 185 insertions(+), 103 deletions(-)
include/net/bluetooth/smp.h +8 -1
index a9ba72c..15b97d5 100644
@@ -116,13 +116,18 @@ struct smp_cmd_security_req {
 #define SMP_MAX_ENC_KEY_SIZE		16
 
 struct smp_chan {
+	struct l2cap_conn *conn;
 	u8		preq[7]; /* SMP Pairing Request */
 	u8		prsp[7]; /* SMP Pairing Response */
-	u8		prnd[16]; /* SMP Pairing Random */
+	u8              prnd[16]; /* SMP Pairing Random (local) */
+	u8              rrnd[16]; /* SMP Pairing Random (remote) */
 	u8		pcnf[16]; /* SMP Pairing Confirm */
 	u8		tk[16]; /* SMP Temporary Key */
 	u8		smp_key_size;
 	struct crypto_blkcipher	*tfm;
+	struct work_struct confirm;
+	struct work_struct random;
+
 };
 
 /* SMP Commands */
@@ -130,4 +135,6 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level);
 int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb);
 int smp_distribute_keys(struct l2cap_conn *conn, __u8 force);
 
+void smp_chan_destroy(struct l2cap_conn *conn);
+
 #endif /* __SMP_H */
net/bluetooth/l2cap_core.c +1 -1
index 09ca51e..566c880 100644
@@ -996,7 +996,7 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)
 
 	if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &hcon->pend)) {
 		del_timer(&conn->security_timer);
-		hci_conn_put(hcon);
+		smp_chan_destroy(conn);
 	}
 
 	hcon->l2cap_data = NULL;
net/bluetooth/smp.c +176 -101

362 lines not on this page · raw message

Signature · 1 line
1.7.6.1
#3 lore raw

Re: [PATCH v2 2/2] Bluetooth: Move SMP crypto functions to a workqueue

Hi Vinicius,

Quoted 10 lines · Vinicius Costa Gomes

The function crypto_blkcipher_setkey() called by smp_e() can sleep, so all the crypto work has to be moved to hci_dev workqueue.

---
 include/net/bluetooth/smp.h |    9 ++-
 net/bluetooth/l2cap_core.c  |    2 +-
 net/bluetooth/smp.c         |  277 +++++++++++++++++++++++++++----------------
 3 files changed, 185 insertions(+), 103 deletions(-)

These two patches have been applied. Thanks.

btw, my tree is now hosted at https://github.com/padovan/bluetooth-next

Gustavo