Bluetooth: Convert SMP to use l2cap_chan
Subsystems (2)
cover Bluetooth: Convert SMP to use l2cap_chan
Hi,
With this patches we do the initial conversion of SMP to use l2cap_chan and its related callbacks. There are many more simplifications possible after this, but to keep the conversion minimal I haven't done those yet. To keep the code compiling and functional between each patch the code that introduces the initial callbacks uses a custom 0x1f CID not to intefere with the legacy SMP CID handling. Only in the last patch which adds fully functional SMP handling through l2cap_chan is this custom CID converted back to the proper L2CAP_CID_SMP.
Johan
----------------------------------------------------------------
Johan Hedberg (4):
Bluetooth: Add more L2CAP convenience callbacks
Bluetooth: Add SMP L2CAP channel skeleton
Bluetooth: Make AES crypto context private to SMP
Bluetooth: Convert SMP to use l2cap_chan infrastructure
include/net/bluetooth/hci_core.h | 2 +- include/net/bluetooth/l2cap.h | 27 +++- net/bluetooth/hci_core.c | 13 +- net/bluetooth/l2cap_core.c | 10 -- net/bluetooth/smp.c | 280 +++++++++++++++++++++++++++-------- net/bluetooth/smp.h | 6 +- 6 files changed, 248 insertions(+), 90 deletions(-)
PATCH 1/4 Bluetooth: Add more L2CAP convenience callbacks
From: Johan Hedberg <[email protected]>
In preparation for converting SMP to use l2cap_chan it's useful to add a few more callback helpers so that smp.c won't need to define all of its own.
--- include/net/bluetooth/l2cap.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
include/net/bluetooth/l2cap.h +25 -0
@@ -838,18 +838,43 @@ static inline struct l2cap_chan *l2cap_chan_no_new_connection(struct l2cap_chanreturn NULL ; } +static inline int l2cap_chan_no_recv (struct l2cap_chan *chan,struct sk_buff *skb) +{ +return -ENOSYS ; +} + +static inline struct sk_buff *l2cap_chan_no_alloc_skb (struct l2cap_chan *chan, +unsigned long hdr_len, +unsigned long len,int nb) +{ +return ERR_PTR (-ENOSYS ); +} +static inline void l2cap_chan_no_teardown (struct l2cap_chan *chan,int err) { } +static inline void l2cap_chan_no_close (struct l2cap_chan *chan) +{ +} +static inline void l2cap_chan_no_ready (struct l2cap_chan *chan) { } +static inline void l2cap_chan_no_state_change (struct l2cap_chan *chan, +int state,int err) +{ +} +static inline void l2cap_chan_no_defer (struct l2cap_chan *chan) { } +static inline void l2cap_chan_no_suspend (struct l2cap_chan *chan) +{ +} +static inline void l2cap_chan_no_resume (struct l2cap_chan *chan) { }
Signature · 1 line
1.9.3
PATCH 2/4 Bluetooth: Add SMP L2CAP channel skeleton
In reply to [email protected]From: Johan Hedberg <[email protected]>
This patch creates the initial SMP L2CAP channels and a skeleton for their callbacks. There is one per-adapter channel created upon adapter registration, and then one channel per-connection created through the new_connection callback. The channels are registered with the reserved CID 0x1f for now in order to not conflict with existing SMP functionality. Once everything is in place the value can be changed to what it should be, i.e. L2CAP_CID_SMP.
--- include/net/bluetooth/hci_core.h | 1 + include/net/bluetooth/l2cap.h | 1 + net/bluetooth/smp.c | 131 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 132 insertions(+), 1 deletion(-)
include/net/bluetooth/hci_core.h +1 -0
@@ -303,6 +303,7 @@ struct hci_dev {__u32 req_result;struct crypto_blkcipher *tfm_aes; +void *smp_data;struct discovery_state discovery;struct hci_conn_hash conn_hash;
include/net/bluetooth/l2cap.h +1 -0
@@ -637,6 +637,7 @@ struct l2cap_conn {struct delayed_work security_timer;struct smp_chan *smp_chan; +struct l2cap_chan *smp;struct list_head chan_l;struct mutex chan_lock;
net/bluetooth/smp.c +130 -1
153 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH 3/4 Bluetooth: Make AES crypto context private to SMP
In reply to [email protected]From: Johan Hedberg <[email protected]>
Now that we have per-adapter SMP data thanks to the root SMP L2CAP channel we can take advantage of it and attach the AES crypto context (only used for SMP) to it. This means that the smp_irk_matches() and smp_generate_rpa() function can be converted to internally handle the AES context.
--- include/net/bluetooth/hci_core.h | 1 - net/bluetooth/hci_core.c | 13 ++----------- net/bluetooth/smp.c | 41 +++++++++++++++++++++++++++------------- net/bluetooth/smp.h | 5 ++--- 4 files changed, 32 insertions(+), 28 deletions(-)
include/net/bluetooth/hci_core.h +0 -1
@@ -302,7 +302,6 @@ struct hci_dev {__u32 req_status;__u32 req_result; -struct crypto_blkcipher *tfm_aes;void *smp_data;struct discovery_state discovery;
net/bluetooth/hci_core.c +2 -11
@@ -3234,11 +3234,8 @@ struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa)return irk; } -if (!hdev->tfm_aes) -return NULL ; -list_for_each_entry (irk, &hdev->identity_resolving_keys, list) { -if (smp_irk_matches (hdev->tfm_aes, irk->val, rpa)) { +if (smp_irk_matches (hdev, irk->val, rpa)) {bacpy (&irk->rpa, rpa);return irk; }
@@ -3887,13 +3884,7 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy, !bacmp(&hdev->random_addr, &hdev->rpa))return 0 ; -if (!hdev->tfm_aes) { -BT_ERR ("%s crypto not available to generate RPA" , - hdev->name); -return -EOPNOTSUPP ; - } - - err =smp_generate_rpa (hdev->tfm_aes, hdev->irk, &hdev->rpa); + err =smp_generate_rpa (hdev, hdev->irk, &hdev->rpa);if (err <0 ) {BT_ERR ("%s failed to generate new RPA" , hdev->name);return err;
net/bluetooth/smp.c +28 -13
90 lines not on this page · raw message
net/bluetooth/smp.h +2 -3
@@ -132,9 +132,8 @@ int smp_user_confirm_reply(struct hci_conn *conn, u16 mgmt_op, __le32 passkey);void smp_chan_destroy (struct l2cap_conn *conn); -bool smp_irk_matches (struct crypto_blkcipher *tfm,u8 irk[16 ], -bdaddr_t *bdaddr); -int smp_generate_rpa (struct crypto_blkcipher *tfm,u8 irk[16 ],bdaddr_t *rpa); +bool smp_irk_matches (struct hci_dev *hdev,u8 irk[16 ],bdaddr_t *bdaddr); +int smp_generate_rpa (struct hci_dev *hdev,u8 irk[16 ],bdaddr_t *rpa);int smp_register (struct hci_dev *hdev);void smp_unregister (struct hci_dev *hdev);
Signature · 1 line
1.9.3
PATCH 4/4 Bluetooth: Convert SMP to use l2cap_chan infrastructure
In reply to [email protected]From: Johan Hedberg <[email protected]>
Now that we have all the necessary pieces in place we can fully convert SMP to use the L2CAP channel infrastructure. This patch adds the necessary callbacks and removes the now unneeded conn->smp_chan pointer.
One notable behavioral change in this patch comes from the following code snippet:
- case L2CAP_CID_SMP:
- if (smp_sig_channel(conn, skb))
- l2cap_conn_del(conn->hcon, EACCES);
This piece of code was essentially forcing a disconnection if garbage SMP data was received. The l2cap_conn_del() function is private to l2cap_conn.c so we don't have access to it anymore when using the L2CAP channel callbacks. Therefore, the behavior of the new code is simply to return errors in the recv() callback (which is simply the old smp_sig_channel()), but no disconnection will occur.
--- include/net/bluetooth/l2cap.h | 1 - net/bluetooth/l2cap_core.c | 10 ---- net/bluetooth/smp.c | 122 +++++++++++++++++++++++------------------- net/bluetooth/smp.h | 1 - 4 files changed, 66 insertions(+), 68 deletions(-)
include/net/bluetooth/l2cap.h +0 -1
@@ -636,7 +636,6 @@ struct l2cap_conn {__u8 disc_reason;struct delayed_work security_timer; -struct smp_chan *smp_chan;struct l2cap_chan *smp;struct list_head chan_l;
net/bluetooth/l2cap_core.c +0 -10
@@ -1651,11 +1651,6 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)if (conn->info_state &L2CAP_INFO_FEAT_MASK_REQ_SENT )cancel_delayed_work_sync (&conn->info_timer); -if (test_and_clear_bit (HCI_CONN_LE_SMP_PEND , &hcon->flags)) { -cancel_delayed_work_sync (&conn->security_timer); -smp_chan_destroy (conn); - } - hcon->l2cap_data =NULL ; conn->hchan =NULL ;l2cap_conn_put (conn);
@@ -6862,11 +6857,6 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb)l2cap_le_sig_channel (conn, skb);break ; -case L2CAP_CID_SMP : -if (smp_sig_channel (conn, skb)) -l2cap_conn_del (conn->hcon,EACCES ); -break ; -default :l2cap_data_channel (conn, cid, skb);break ;
net/bluetooth/smp.c +66 -56
287 lines not on this page · raw message
net/bluetooth/smp.h +0 -1
@@ -126,7 +126,6 @@ enum {/* SMP Commands */ bool smp_sufficient_security (struct hci_conn *hcon,u8 sec_level);int smp_conn_security (struct hci_conn *hcon,__u8 sec_level); -int smp_sig_channel (struct l2cap_conn *conn,struct sk_buff *skb);int smp_distribute_keys (struct l2cap_conn *conn);int smp_user_confirm_reply (struct hci_conn *conn,u16 mgmt_op,__le32 passkey);
Signature · 1 line
1.9.3
Marcel Holtmann
maintainerHi Johan,
Quoted 18 lines
With this patches we do the initial conversion of SMP to use
l2cap_chanand its related callbacks. There are many more simplifications possible after this, but to keep the conversion minimal I haven't done those yet. To keep the code compiling and functional between each patch the code that introduces the initial callbacks uses a custom0x1fCID not to intefere with the legacy SMP CID handling. Only in the last patch which adds fully functional SMP handling throughl2cap_chanis this custom CID converted back to the properL2CAP_CID_SMP.Johan
----------------------------------------------------------------
Johan Hedberg (4):
Bluetooth: Add more L2CAP convenience callbacks
Bluetooth: Add SMP L2CAP channel skeleton
Bluetooth: Make AES crypto context private to SMP
Bluetooth: Convert SMP to usel2cap_chaninfrastructure
Quoted 7 lines
include/net/bluetooth/hci_core.h | 2 +- include/net/bluetooth/l2cap.h | 27 +++- net/bluetooth/hci_core.c | 13 +- net/bluetooth/l2cap_core.c | 10 -- net/bluetooth/smp.c | 280 +++++++++++++++++++++++++++-------- net/bluetooth/smp.h | 6 +- 6 files changed, 248 insertions(+), 90 deletions(-)
all 4 patches have been applied to bluetooth-next tree.
Regards
Marcel