Move SMP encryption to a workqueue
Subsystems (2)
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
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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 2/2 Bluetooth: Move SMP crypto functions to a workqueue
In reply to Vinicius Costa GomesThe 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
@@ -116,13 +116,18 @@ struct smp_cmd_security_req {#define SMP_MAX_ENC_KEY_SIZE 16struct 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
@@ -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
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 bysmp_e()can sleep, so all the crypto work has to be moved tohci_devworkqueue.Signed-off-by Vinicius Costa Gomes <[email protected]>--- 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