SMP Just Works Implementation
Subsystems (2)
cover SMP Just Works Implementation
Hi,
This patch series implement the Just Works SMP procedures for LE links.
These patches can also be reached from here[1].
Cheers,
--
Vinicius
[1] http://git.infradead.org/users/vcgomes/linux-2.6.git (for-next branch)
Anderson Briglia (7):
Bluetooth: Implement the first SMP commands
Bluetooth: Start SMP procedure
Bluetooth: simple SMP pairing negotiation
Bluetooth: LE SMP Cryptoolbox functions
Bluetooth: Add SMP confirmation structs
Bluetooth: Add SMP confirmation checks methods
Bluetooth: Minor fix in SMP methods
Vinicius Costa Gomes (8):
Bluetooth: Add support for using the crypto subsystem
Bluetooth: Add support for LE Start Encryption
Bluetooth: Add support for resuming socket when SMP is finished
Bluetooth: Fix initial security level of LE links
Bluetooth: Update the security level when link is encrypted
Bluetooth: Add support for Pairing features exchange
Bluetooth: Add support for SMP timeout
Bluetooth: Add key size checks for SMP
include/net/bluetooth/hci.h | 34 +++ include/net/bluetooth/hci_core.h | 10 + include/net/bluetooth/l2cap.h | 9 + include/net/bluetooth/smp.h | 46 ++++ net/bluetooth/Kconfig | 6 + net/bluetooth/Makefile | 2 +- net/bluetooth/hci_conn.c | 47 ++++ net/bluetooth/hci_core.c | 22 ++ net/bluetooth/hci_event.c | 69 +++++ net/bluetooth/l2cap_core.c | 137 ++++++---- net/bluetooth/l2cap_sock.c | 17 ++ net/bluetooth/smp.c | 535 ++++++++++++++++++++++++++++++++++++++ 12 files changed, 876 insertions(+), 58 deletions(-) create mode 100644 net/bluetooth/smp.c
--
1.7.4.1
PATCH 1/15 Bluetooth: Implement the first SMP commands
From: Anderson Briglia <[email protected]>
These simple commands will allow the SMP procedure to be started and terminated with a not supported error. This is the first step toward something useful.
--- include/net/bluetooth/smp.h | 26 ++++++++ net/bluetooth/Makefile | 2 +- net/bluetooth/smp.c | 146 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+), 1 deletions(-) create mode 100644 net/bluetooth/smp.c
include/net/bluetooth/smp.h +26 -0
@@ -1,3 +1,25 @@ +/* +BlueZ - Bluetooth protocol stack for Linux +Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License version 2 as +published by the Free Software Foundation; + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. +IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY +CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, +COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS +SOFTWARE IS DISCLAIMED. +*/ +#ifndef __SMP_H#define __SMP_H
@@ -73,4 +95,8 @@ struct smp_cmd_security_req {#define SMP_UNSPECIFIED 0x08#define SMP_REPEATED_ATTEMPTS 0x09 +/* 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); +#endif /* __SMP_H */
net/bluetooth/Makefile +1 -1
@@ -9,5 +9,5 @@ obj-$(CONFIG_BT_CMTP) += cmtp/ obj-$(CONFIG_BT_HIDP) += hidp/ bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o hci_sock.o hci_sysfs.o lib.o -bluetooth-$(CONFIG_BT_L2CAP) += l2cap_core.o l2cap_sock.o +bluetooth-$(CONFIG_BT_L2CAP) += l2cap_core.o l2cap_sock.o smp.o bluetooth-$(CONFIG_BT_SCO) += sco.o
net/bluetooth/smp.c new file +146 -0
146 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 2/15 Bluetooth: Start SMP procedure
In reply to Vinicius Costa GomesFrom: Anderson Briglia <[email protected]>
Start SMP procedure for LE connections. This modification intercepts l2cap received frames and call proper SMP functions to start the SMP procedure. By now, no keys are being used.
--- net/bluetooth/l2cap_core.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
net/bluetooth/l2cap_core.c +8 -0
@@ -54,6 +54,7 @@#include <net/bluetooth/bluetooth.h> #include <net/bluetooth/hci_core.h> #include <net/bluetooth/l2cap.h> +#include <net/bluetooth/smp.h> int disable_ertm;
@@ -684,6 +685,8 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)l2cap_sock_clear_timer (sk); sk->sk_state =BT_CONNECTED ; sk->sk_state_change (sk); +if (smp_conn_security (conn,l2cap_pi (sk)->sec_level)) +BT_DBG ("Insufficient security" ); } if (sk->sk_type != SOCK_SEQPACKET &&
@@ -3673,6 +3676,11 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb)l2cap_conless_channel (conn, psm, 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 ;
Signature · 1 line
1.7.4.1
PATCH 3/15 Bluetooth: simple SMP pairing negotiation
In reply to Vinicius Costa GomesFrom: Anderson Briglia <[email protected]>
This implementation only exchanges SMP messages between the Host and the Remote. No keys are being generated. TK and STK generation will be provided in further patches.
--- include/net/bluetooth/smp.h | 17 +++++++ net/bluetooth/smp.c | 106 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 118 insertions(+), 5 deletions(-)
include/net/bluetooth/smp.h +17 -0
@@ -38,6 +38,23 @@ struct smp_cmd_pairing {__u8 resp_key_dist; } __packed; +#define SMP_IO_DISPLAY_ONLY 0x00 +#define SMP_IO_DISPLAY_YESNO 0x01 +#define SMP_IO_KEYBOARD_ONLY 0x02 +#define SMP_IO_NO_INPUT_OUTPUT 0x03 +#define SMP_IO_KEYBOARD_DISPLAY 0x04 + +#define SMP_OOB_NOT_PRESENT 0x00 +#define SMP_OOB_PRESENT 0x01 + +#define SMP_DIST_ENC_KEY 0x01 +#define SMP_DIST_ID_KEY 0x02 +#define SMP_DIST_SIGN 0x04 + +#define SMP_AUTH_NONE 0x00 +#define SMP_AUTH_BONDING 0x01 +#define SMP_AUTH_MITM 0x04 +#define SMP_CMD_PAIRING_CONFIRM 0x03struct smp_cmd_pairing_confirm {__u8 confirm_val[16 ];
net/bluetooth/smp.c +101 -5
131 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 4/15 Bluetooth: Add support for using the crypto subsystem
In reply to Vinicius Costa GomesThis will allow using the crypto subsystem for encrypting data. As SMP (Security Manager Protocol) is implemented almost entirely on the host side and the crypto module already implements the needed methods (AES-128), it makes sense to use it.
This patch also adds a new Kconfig option to toggle the SMP support.
--- include/net/bluetooth/hci_core.h | 2 ++ net/bluetooth/Kconfig | 6 ++++++ net/bluetooth/hci_core.c | 22 ++++++++++++++++++++++ net/bluetooth/smp.c | 17 +++++++++++++++-- 4 files changed, 45 insertions(+), 2 deletions(-)
include/net/bluetooth/hci_core.h +2 -0
@@ -161,6 +161,8 @@ 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;
net/bluetooth/Kconfig +6 -0
@@ -22,6 +22,7 @@ menuconfig BT BNEP Module (Bluetooth Network Encapsulation Protocol) CMTP Module (CAPI Message Transport Protocol) HIDP Module (Human Interface Device Protocol) + SMP Module (Security Manager Protocol) Say Y here to compile Bluetooth support into the kernel or say M to compile it as module (bluetooth).
@@ -35,11 +36,16 @@ config BT_L2CAP bool "L2CAP protocol support" depends on BT select CRC16 + select CRYPTO_BLKCIPHER + select CRYPTO_AES help L2CAP (Logical Link Control and Adaptation Protocol) provides connection oriented and connection-less data transport. L2CAP support is required for most Bluetooth applications. + Also included is support for SMP (Security Manager Protocol) which + is the security layer on top of LE (Low Energy) links. + config BT_SCO bool "SCO links support" depends on BT
net/bluetooth/hci_core.c +22 -0
@@ -42,6 +42,7 @@#include <linux/notifier.h> #include <linux/rfkill.h> #include <linux/timer.h> +#include <linux/crypto.h> #include <net/sock.h> #include <asm/system.h>
@@ -60,6 +61,8 @@ static void hci_notify(struct hci_dev *hdev, int event);static DEFINE_RWLOCK (hci_task_lock); +static int enable_smp; +/* HCI device list */ LIST_HEAD (hci_dev_list);DEFINE_RWLOCK (hci_dev_list_lock);
@@ -1077,6 +1080,14 @@ static void hci_cmd_timer(unsigned long arg)tasklet_schedule (&hdev->cmd_task); } +static struct crypto_blkcipher *alloc_cypher (void ) +{ +if (enable_smp) +return crypto_alloc_blkcipher ("ecb(aes)" ,0 ,CRYPTO_ALG_ASYNC ); + +return ERR_PTR (-ENOTSUPP ); +} +/* Register HCI device */ int hci_register_dev (struct hci_dev *hdev) {
@@ -1155,6 +1166,11 @@ int hci_register_dev(struct hci_dev *hdev)if (!hdev->workqueue) goto nomem; + hdev->tfm =alloc_cypher (); +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,
@@ -1203,6 +1219,9 @@ 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) {
@@ -2037,3 +2056,6 @@ static void hci_cmd_task(unsigned long arg) } } } + +module_param (enable_smp, bool,0644 ); +MODULE_PARM_DESC (enable_smp,"Enable SMP support (LE only)" );
net/bluetooth/smp.c +15 -2
@@ -157,6 +157,9 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level)BT_DBG ("conn %p hcon %p level 0x%2.2x" , conn, conn->hcon, sec_level); +if (IS_ERR (conn->hcon->hdev->tfm)) +return PTR_ERR (conn->hcon->hdev->tfm); +switch (sec_level) {case BT_SECURITY_MEDIUM :/* Encrypted, no MITM protection */
@@ -197,6 +200,12 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)__u8 reason;int err =0 ; +if (IS_ERR (conn->hcon->hdev->tfm)) { + err =PTR_ERR (conn->hcon->hdev->tfm); + reason =SMP_PAIRING_NOTSUPP ; + goto done; + } +skb_pull (skb,sizeof (code));switch (code) {
@@ -232,11 +241,15 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)BT_DBG ("Unknown command code 0x%2.2x" , code); reason =SMP_CMD_NOTSUPP ; -smp_send_cmd (conn,SMP_CMD_PAIRING_FAIL ,sizeof (reason), - &reason); err = -EOPNOTSUPP ; + goto done; } +done: +if (reason) +smp_send_cmd (conn,SMP_CMD_PAIRING_FAIL ,sizeof (reason), + &reason); +kfree_skb (skb);return err; }
Signature · 1 line
1.7.4.1
Re: [bluetooth-next 04/15] Bluetooth: Add support for using the crypto subsystem
Hi Vinicius,
Quoted 117 lines · Vinicius Costa Gomes
This will allow using the crypto subsystem for encrypting data. As SMP (Security Manager Protocol) is implemented almost entirely on the host side and the crypto module already implements the needed methods (AES-128), it makes sense to use it.
This patch also adds a new
Kconfigoption to toggle the SMP support.Signed-off-by Vinicius Costa Gomes <[email protected]>Signed-off-by Anderson Briglia <[email protected]>--- include/net/bluetooth/hci_core.h | 2 ++ net/bluetooth/Kconfig | 6 ++++++ net/bluetooth/hci_core.c | 22 ++++++++++++++++++++++ net/bluetooth/smp.c | 17 +++++++++++++++-- 4 files changed, 45 insertions(+), 2 deletions(-)include/net/bluetooth/hci_core.h +2
-0@@ -161,6 +161,8 @@ 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;net/bluetooth/Kconfig +6
-0@@ -22,6 +22,7 @@ menuconfig BT BNEP Module (Bluetooth Network Encapsulation Protocol) CMTP Module (CAPI Message Transport Protocol) HIDP Module (Human Interface Device Protocol) + SMP Module (Security Manager Protocol) Say Y here to compile Bluetooth support into the kernel or say M to compile it as module (bluetooth).@@ -35,11 +36,16 @@ config BT_L2CAP bool "L2CAP protocol support" depends on BT select CRC16 + select CRYPTO_BLKCIPHER + select CRYPTO_AES help L2CAP (Logical Link Control and Adaptation Protocol) provides connection oriented and connection-less data transport. L2CAP support is required for most Bluetooth applications. + Also included is support for SMP (Security Manager Protocol) which + is the security layer on top of LE (Low Energy) links. + config BT_SCO bool "SCO links support" depends on BTnet/bluetooth/hci_core.c +19
-0@@ -42,6 +42,7 @@#include <linux/notifier.h> #include <linux/rfkill.h> #include <linux/timer.h> +#include <linux/crypto.h> #include <net/sock.h> #include <asm/system.h> @@ -60,6 +61,8 @@ static void hci_notify(struct hci_dev *hdev, int event);static DEFINE_RWLOCK (hci_task_lock); +static int enable_smp; +/* HCI device list */ LIST_HEAD (hci_dev_list);DEFINE_RWLOCK (hci_dev_list_lock);@@ -1077,6 +1080,14 @@ static void hci_cmd_timer(unsigned long arg)tasklet_schedule (&hdev->cmd_task); } +static struct crypto_blkcipher *alloc_cypher (void ) +{ +if (enable_smp) +return crypto_alloc_blkcipher ("ecb(aes)" ,0 ,CRYPTO_ALG_ASYNC ); + +return ERR_PTR (-ENOTSUPP ); +} +/* Register HCI device */ int hci_register_dev (struct hci_dev *hdev) {@@ -1155,6 +1166,11 @@ int hci_register_dev(struct hci_dev *hdev)if (!hdev->workqueue) goto nomem; + hdev->tfm =alloc_cypher (); +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,@@ -1203,6 +1219,9 @@ 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/hci_core.c static void hci_cmd_task(unsigned long arg) · line 2061
Quoted 6 lines
net/bluetooth/hci_core.c +3
-0@@ -2037,3 +2056,6 @@ static void hci_cmd_task(unsigned long arg) } } } + +module_param (enable_smp, bool,0644 ); +MODULE_PARM_DESC (enable_smp,"Enable SMP support (LE only)" );
This all should be obviously inside smp.c
Regards,
Signature · 2 lines
Gustavo F. Padovan http://profusion.mobi
Re: [bluetooth-next 04/15] Bluetooth: Add support for using the crypto subsystem
Hi Gustavo,
Quoted 119 lines · Gustavo F. Padovan
Hi Vinicius,
Quoted 115 lines · Vinicius Costa Gomes
This will allow using the crypto subsystem for encrypting data. As SMP (Security Manager Protocol) is implemented almost entirely on the host side and the crypto module already implements the needed methods (AES-128), it makes sense to use it.
This patch also adds a new
Kconfigoption to toggle the SMP support.Signed-off-by Vinicius Costa Gomes <[email protected]>Signed-off-by Anderson Briglia <[email protected]>---
include/net/bluetooth/hci_core.h | 2 ++net/bluetooth/Kconfig| 6 ++++++net/bluetooth/hci_core.c| 22 ++++++++++++++++++++++net/bluetooth/smp.c| 17 +++++++++++++++--4 files changed, 45 insertions(+), 2 deletions(-)include/net/bluetooth/hci_core.h +2
-0@@ -161,6 +161,8 @@ 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;net/bluetooth/Kconfig +1
-0@@ -22,6 +22,7 @@ menuconfig BT BNEP Module (Bluetooth Network Encapsulation Protocol) CMTP Module (CAPI Message Transport Protocol) HIDP Module (Human Interface Device Protocol) + SMP Module (Security Manager Protocol)Say Y here to compile Bluetooth support into the kernel or say M to compile it as module (bluetooth).
net/bluetooth/Kconfig +0
-0@@ -35,11 +36,16 @@ config BT_L2CAPbool "L2CAP protocol support"
depends on BT
select CRC16
+ selectCRYPTO_BLKCIPHER
+ selectCRYPTO_AES
help
L2CAP (Logical Link Control and Adaptation Protocol) provides connection oriented and connection-less data transport. L2CAP support is required for most Bluetooth applications.+ Also included is support for SMP (Security Manager Protocol) which
+ is the security layer on top of LE (Low Energy) links. +
configBT_SCO
bool "SCO links support"
depends on BTnet/bluetooth/hci_core.c +19
-0@@ -42,6 +42,7 @@ #include <linux/notifier.h> #include <linux/rfkill.h> #include <linux/timer.h> +#include <linux/crypto.h> #include <net/sock.h> #include <asm/system.h>@@ -60,6 +61,8 @@ static void hci_notify(struct hci_dev *hdev, int event); static DEFINE_RWLOCK(hci_task_lock); +static int enable_smp; + /* HCI device list */ LIST_HEAD(hci_dev_list); DEFINE_RWLOCK(hci_dev_list_lock);@@ -1077,6 +1080,14 @@ static void hci_cmd_timer(unsigned long arg) tasklet_schedule(&hdev->cmd_task); } +static struct crypto_blkcipher *alloc_cypher (void ) +{ + if (enable_smp) + return crypto_alloc_blkcipher("ecb(aes)", 0, CRYPTO_ALG_ASYNC); + + return ERR_PTR(-ENOTSUPP); +} + /* Register HCI device */ int hci_register_dev(struct hci_dev *hdev) {@@ -1155,6 +1166,11 @@ int hci_register_dev(struct hci_dev *hdev) if (!hdev->workqueue) goto nomem; + hdev->tfm = alloc_cypher(); + 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,@@ -1203,6 +1219,9 @@ 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);
Quoted 10 lines
net/bluetooth/hci_core.c static void hci_cmd_task(unsigned long arg) · line 2061
Quoted 8 lines
net/bluetooth/hci_core.c +3
-0if (hdev->rfkill) {@@ -2037,3 +2056,6 @@ static void hci_cmd_task(unsigned long arg) } } } + +module_param (enable_smp, bool,0644 ); +MODULE_PARM_DESC (enable_smp,"Enable SMP support (LE only)" );This all should be obviously inside
smp.c
I have a couple of points against it:
1. it's only used for one purpose, it says whether to try or not to allocate the block cypher, which is done during the adapter registration;
2. If the current way is ok, it would mean that I would need to export another method from smp.c, that was something that I tried to minimize;
3. and my weakest argument, seems that there are other similar uses, for example enable_mgmt.
But if you think the code will be clearer moving that to smp.c, will be glad to change.
Quoted 7 lines
Regards,
--
Gustavo F. Padovan
http://profusion.mobi
Cheers,
Signature · 1 line
Vinicius
Re: [bluetooth-next 04/15] Bluetooth: Add support for using the crypto subsystem
Hi Vinicius,
Quoted 140 lines · Vinicius Gomes
Hi Gustavo,
Quoted 119 lines · Gustavo F. Padovan
Hi Vinicius,
Quoted 115 lines · Vinicius Costa Gomes
This will allow using the crypto subsystem for encrypting data. As SMP (Security Manager Protocol) is implemented almost entirely on the host side and the crypto module already implements the needed methods (AES-128), it makes sense to use it.
This patch also adds a new
Kconfigoption to toggle the SMP support.Signed-off-by Vinicius Costa Gomes <[email protected]>Signed-off-by Anderson Briglia <[email protected]>---
include/net/bluetooth/hci_core.h | 2 ++net/bluetooth/Kconfig| 6 ++++++net/bluetooth/hci_core.c| 22 ++++++++++++++++++++++net/bluetooth/smp.c| 17 +++++++++++++++--4 files changed, 45 insertions(+), 2 deletions(-)include/net/bluetooth/hci_core.h +2
-0@@ -161,6 +161,8 @@ 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;net/bluetooth/Kconfig +1
-0@@ -22,6 +22,7 @@ menuconfig BT BNEP Module (Bluetooth Network Encapsulation Protocol) CMTP Module (CAPI Message Transport Protocol) HIDP Module (Human Interface Device Protocol) + SMP Module (Security Manager Protocol)Say Y here to compile Bluetooth support into the kernel or say M to compile it as module (bluetooth).
net/bluetooth/Kconfig +0
-0@@ -35,11 +36,16 @@ config BT_L2CAPbool "L2CAP protocol support"
depends on BT
select CRC16
+ selectCRYPTO_BLKCIPHER
+ selectCRYPTO_AES
help
L2CAP (Logical Link Control and Adaptation Protocol) provides connection oriented and connection-less data transport. L2CAP support is required for most Bluetooth applications.+ Also included is support for SMP (Security Manager Protocol) which
+ is the security layer on top of LE (Low Energy) links. +
configBT_SCO
bool "SCO links support"
depends on BTnet/bluetooth/hci_core.c +19
-0@@ -42,6 +42,7 @@ #include <linux/notifier.h> #include <linux/rfkill.h> #include <linux/timer.h> +#include <linux/crypto.h> #include <net/sock.h> #include <asm/system.h>@@ -60,6 +61,8 @@ static void hci_notify(struct hci_dev *hdev, int event); static DEFINE_RWLOCK(hci_task_lock); +static int enable_smp; + /* HCI device list */ LIST_HEAD(hci_dev_list); DEFINE_RWLOCK(hci_dev_list_lock);@@ -1077,6 +1080,14 @@ static void hci_cmd_timer(unsigned long arg) tasklet_schedule(&hdev->cmd_task); } +static struct crypto_blkcipher *alloc_cypher (void ) +{ + if (enable_smp) + return crypto_alloc_blkcipher("ecb(aes)", 0, CRYPTO_ALG_ASYNC); + + return ERR_PTR(-ENOTSUPP); +} + /* Register HCI device */ int hci_register_dev(struct hci_dev *hdev) {@@ -1155,6 +1166,11 @@ int hci_register_dev(struct hci_dev *hdev) if (!hdev->workqueue) goto nomem; + hdev->tfm = alloc_cypher(); + 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,@@ -1203,6 +1219,9 @@ 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);Quoted 10 lines
net/bluetooth/hci_core.c static void hci_cmd_task(unsigned long arg) · line 2061
Quoted 8 lines
net/bluetooth/hci_core.c +3
-0if (hdev->rfkill) {@@ -2037,3 +2056,6 @@ static void hci_cmd_task(unsigned long arg) } } } + +module_param (enable_smp, bool,0644 ); +MODULE_PARM_DESC (enable_smp,"Enable SMP support (LE only)" );This all should be obviously inside
smp.cI have a couple of points against it:
1. it's only used for one purpose, it says whether to try or not to allocate the block cypher, which is done during the adapter registration;
Quoted 6 lines
2. If the current way is ok, it would mean that I would need to export another method from
smp.c, that was something that I tried to minimize;3. and my weakest argument, seems that there are other similar uses, for example
enable_mgmt.
A similar example here is enable_ertm inside l2cap_core.c. It's a L2CAP related option and should reside inside L2CAP code.
Quoted 3 lines
But if you think the code will be clearer moving that to
smp.c, will be glad to change.
I don't see the point on have it on hci code. SMP and Block cypher has not much to do with HCI. I prefer it on smp.c
Signature · 2 lines
Gustavo F. Padovan http://profusion.mobi
Re: [bluetooth-next 04/15] Bluetooth: Add support for using the crypto subsystem
Quoted 4 lines · Gustavo F. Padovan
Hi Vinicius,
* Vinicius Gomes <[email protected]> [2011-02-27 21:49:39 -0300]:
[ ... ]
Quoted 18 lines
Quoted 7 lines
I have a couple of points against it:
1. it's only used for one purpose, it says whether to try or not to allocate the block cypher, which is done during the adapter registration;
Quoted 6 lines
2. If the current way is ok, it would mean that I would need to export another method from
smp.c, that was something that I tried to minimize;3. and my weakest argument, seems that there are other similar uses, for example
enable_mgmt.A similar example here is
enable_ertminsidel2cap_core.c. It's a L2CAP related option and should reside inside L2CAP code.Quoted 1 line
Quoted 5 lines
Quoted 2 lines
But if you think the code will be clearer moving that to
smp.c, will be glad to change.I don't see the point on have it on hci code. SMP and Block cypher has not much to do with HCI. I prefer it on
smp.c
Fair enough. Will change.
Quoted 4 lines
Signature · 3 lines
-- Gustavo F. Padovan http://profusion.mobi
Cheers,
Signature · 1 line
Vinicius
Re: [bluetooth-next 04/15] Bluetooth: Add support for using the crypto subsystem
In reply to Gustavo F. PadovanHi Marcel,
Quoted 155 lines · Gustavo F. Padovan
Hi Vinicius,
Quoted 140 lines · Vinicius Gomes
Hi Gustavo,
Quoted 119 lines · Gustavo F. Padovan
Hi Vinicius,
Quoted 115 lines · Vinicius Costa Gomes
This will allow using the crypto subsystem for encrypting data. As SMP (Security Manager Protocol) is implemented almost entirely on the host side and the crypto module already implements the needed methods (AES-128), it makes sense to use it.
This patch also adds a new
Kconfigoption to toggle the SMP support.Signed-off-by Vinicius Costa Gomes <[email protected]>Signed-off-by Anderson Briglia <[email protected]>---
include/net/bluetooth/hci_core.h | 2 ++net/bluetooth/Kconfig| 6 ++++++net/bluetooth/hci_core.c| 22 ++++++++++++++++++++++net/bluetooth/smp.c| 17 +++++++++++++++--4 files changed, 45 insertions(+), 2 deletions(-)include/net/bluetooth/hci_core.h +2
-0@@ -161,6 +161,8 @@ 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;net/bluetooth/Kconfig +1
-0@@ -22,6 +22,7 @@ menuconfig BT BNEP Module (Bluetooth Network Encapsulation Protocol) CMTP Module (CAPI Message Transport Protocol) HIDP Module (Human Interface Device Protocol) + SMP Module (Security Manager Protocol)Say Y here to compile Bluetooth support into the kernel or say M to compile it as module (bluetooth).
net/bluetooth/Kconfig +0
-0@@ -35,11 +36,16 @@ config BT_L2CAPbool "L2CAP protocol support"
depends on BT
select CRC16
+ selectCRYPTO_BLKCIPHER
+ selectCRYPTO_AES
help
L2CAP (Logical Link Control and Adaptation Protocol) provides connection oriented and connection-less data transport. L2CAP support is required for most Bluetooth applications.+ Also included is support for SMP (Security Manager Protocol) which
+ is the security layer on top of LE (Low Energy) links. +
configBT_SCO
bool "SCO links support"
depends on BTnet/bluetooth/hci_core.c +19
-0@@ -42,6 +42,7 @@ #include <linux/notifier.h> #include <linux/rfkill.h> #include <linux/timer.h> +#include <linux/crypto.h> #include <net/sock.h> #include <asm/system.h>@@ -60,6 +61,8 @@ static void hci_notify(struct hci_dev *hdev, int event); static DEFINE_RWLOCK(hci_task_lock); +static int enable_smp; + /* HCI device list */ LIST_HEAD(hci_dev_list); DEFINE_RWLOCK(hci_dev_list_lock);@@ -1077,6 +1080,14 @@ static void hci_cmd_timer(unsigned long arg) tasklet_schedule(&hdev->cmd_task); } +static struct crypto_blkcipher *alloc_cypher (void ) +{ + if (enable_smp) + return crypto_alloc_blkcipher("ecb(aes)", 0, CRYPTO_ALG_ASYNC); + + return ERR_PTR(-ENOTSUPP); +} + /* Register HCI device */ int hci_register_dev(struct hci_dev *hdev) {@@ -1155,6 +1166,11 @@ int hci_register_dev(struct hci_dev *hdev) if (!hdev->workqueue) goto nomem; + hdev->tfm = alloc_cypher(); + 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,@@ -1203,6 +1219,9 @@ 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);Quoted 10 lines
net/bluetooth/hci_core.c static void hci_cmd_task(unsigned long arg) · line 2061
Quoted 8 lines
net/bluetooth/hci_core.c +3
-0if (hdev->rfkill) {@@ -2037,3 +2056,6 @@ static void hci_cmd_task(unsigned long arg) } } } + +module_param (enable_smp, bool,0644 ); +MODULE_PARM_DESC (enable_smp,"Enable SMP support (LE only)" );This all should be obviously inside
smp.cI have a couple of points against it:
1. it's only used for one purpose, it says whether to try or not to allocate the block cypher, which is done during the adapter registration;
Quoted 6 lines
2. If the current way is ok, it would mean that I would need to export another method from
smp.c, that was something that I tried to minimize;3. and my weakest argument, seems that there are other similar uses, for example
enable_mgmt.A similar example here is
enable_ertminsidel2cap_core.c. It's a L2CAP related option and should reside inside L2CAP code.Quoted 1 line
Quoted 5 lines
Quoted 2 lines
But if you think the code will be clearer moving that to
smp.c, will be glad to change.I don't see the point on have it on hci code. SMP and Block cypher has not much to do with HCI. I prefer it on
smp.c
Gustavo and I were talking on IRC and couldn't come to a solution, so we ask you for some input.
So, just to give a little more context, the problem is that the crypto functions used in SMP depend on the allocation of a block cypher "transform", this allocation must happen during user context.
The current solution is that the allocation is done in hci_core.c during the adapter registration, but only when the enable_smp module parameter is enabled. When the parameter is disabled the allocation method just returns an invalid pointer and everything happens the same as if the allocation has failed.
Gustavo has a preference for an ondemand aproach, for example, using a workqueue for doing the allocation, and trying the allocation just when SMP is going to be used, e.g. when we receive the first SMP message or when some security level is activated for that socket.
Any ideas?
Quoted 4 lines
Signature · 3 lines
-- Gustavo F. Padovan http://profusion.mobi
Cheers,
Signature · 1 line
Vinicius
Re: [bluetooth-next 04/15] Bluetooth: Add support for using the crypto subsystem
Quoted 176 lines · Vinicius Costa Gomes
Hi Marcel,
Quoted 155 lines · Gustavo F. Padovan
Hi Vinicius,
Quoted 140 lines · Vinicius Gomes
Hi Gustavo,
Quoted 119 lines · Gustavo F. Padovan
Hi Vinicius,
Quoted 115 lines · Vinicius Costa Gomes
This will allow using the crypto subsystem for encrypting data. As SMP (Security Manager Protocol) is implemented almost entirely on the host side and the crypto module already implements the needed methods (AES-128), it makes sense to use it.
This patch also adds a new
Kconfigoption to toggle the SMP support.Signed-off-by Vinicius Costa Gomes <[email protected]>Signed-off-by Anderson Briglia <[email protected]>---
include/net/bluetooth/hci_core.h | 2 ++net/bluetooth/Kconfig| 6 ++++++net/bluetooth/hci_core.c| 22 ++++++++++++++++++++++net/bluetooth/smp.c| 17 +++++++++++++++--4 files changed, 45 insertions(+), 2 deletions(-)include/net/bluetooth/hci_core.h +2
-0@@ -161,6 +161,8 @@ 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;net/bluetooth/Kconfig +1
-0@@ -22,6 +22,7 @@ menuconfig BT BNEP Module (Bluetooth Network Encapsulation Protocol) CMTP Module (CAPI Message Transport Protocol) HIDP Module (Human Interface Device Protocol) + SMP Module (Security Manager Protocol)Say Y here to compile Bluetooth support into the kernel or say M to compile it as module (bluetooth).
net/bluetooth/Kconfig +0
-0@@ -35,11 +36,16 @@ config BT_L2CAPbool "L2CAP protocol support"
depends on BT
select CRC16
+ selectCRYPTO_BLKCIPHER
+ selectCRYPTO_AES
help
L2CAP (Logical Link Control and Adaptation Protocol) provides connection oriented and connection-less data transport. L2CAP support is required for most Bluetooth applications.+ Also included is support for SMP (Security Manager Protocol) which
+ is the security layer on top of LE (Low Energy) links. +
configBT_SCO
bool "SCO links support"
depends on BTnet/bluetooth/hci_core.c +19
-0@@ -42,6 +42,7 @@ #include <linux/notifier.h> #include <linux/rfkill.h> #include <linux/timer.h> +#include <linux/crypto.h> #include <net/sock.h> #include <asm/system.h>@@ -60,6 +61,8 @@ static void hci_notify(struct hci_dev *hdev, int event); static DEFINE_RWLOCK(hci_task_lock); +static int enable_smp; + /* HCI device list */ LIST_HEAD(hci_dev_list); DEFINE_RWLOCK(hci_dev_list_lock);@@ -1077,6 +1080,14 @@ static void hci_cmd_timer(unsigned long arg) tasklet_schedule(&hdev->cmd_task); } +static struct crypto_blkcipher *alloc_cypher (void ) +{ + if (enable_smp) + return crypto_alloc_blkcipher("ecb(aes)", 0, CRYPTO_ALG_ASYNC); + + return ERR_PTR(-ENOTSUPP); +} + /* Register HCI device */ int hci_register_dev(struct hci_dev *hdev) {@@ -1155,6 +1166,11 @@ int hci_register_dev(struct hci_dev *hdev) if (!hdev->workqueue) goto nomem; + hdev->tfm = alloc_cypher(); + 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,@@ -1203,6 +1219,9 @@ 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);Quoted 10 lines
net/bluetooth/hci_core.c static void hci_cmd_task(unsigned long arg) · line 2061
Quoted 8 lines
net/bluetooth/hci_core.c +3
-0if (hdev->rfkill) {@@ -2037,3 +2056,6 @@ static void hci_cmd_task(unsigned long arg) } } } + +module_param (enable_smp, bool,0644 ); +MODULE_PARM_DESC (enable_smp,"Enable SMP support (LE only)" );This all should be obviously inside
smp.cI have a couple of points against it:
1. it's only used for one purpose, it says whether to try or not to allocate the block cypher, which is done during the adapter registration;
Quoted 6 lines
2. If the current way is ok, it would mean that I would need to export another method from
smp.c, that was something that I tried to minimize;3. and my weakest argument, seems that there are other similar uses, for example
enable_mgmt.A similar example here is
enable_ertminsidel2cap_core.c. It's a L2CAP related option and should reside inside L2CAP code.Quoted 1 line
Quoted 5 lines
Quoted 2 lines
But if you think the code will be clearer moving that to
smp.c, will be glad to change.I don't see the point on have it on hci code. SMP and Block cypher has not much to do with HCI. I prefer it on
smp.cGustavo and I were talking on IRC and couldn't come to a solution, so we ask you for some input.
So, just to give a little more context, the problem is that the crypto functions used in SMP depend on the allocation of a block cypher "transform", this allocation must happen during user context.
The current solution is that the allocation is done in
hci_core.cduring the adapter registration, but only when theenable_smpmodule parameter is enabled. When the parameter is disabled the allocation method just returns an invalid pointer and everything happens the same as if the allocation has failed.
Quoted 6 lines
Gustavo has a preference for an ondemand aproach, for example, using a workqueue for doing the allocation, and trying the allocation just when SMP is going to be used, e.g. when we receive the first SMP message or when some security level is activated for that socket.
Any ideas?
Still no ideas?
Quoted 10 lines
Quoted 5 lines
Signature · 3 lines
-- Gustavo F. Padovan http://profusion.mobiCheers,
Signature · 1 line
Vinicius
Signature · 1 line
Vinicius
Re: [bluetooth-next 04/15] Bluetooth: Add support for using the crypto subsystem
Hi all,
Quoted 177 lines · Vinicius Costa Gomes
Quoted 176 lines · Vinicius Costa Gomes
Hi Marcel,
Quoted 155 lines · Gustavo F. Padovan
Hi Vinicius,
Quoted 140 lines · Vinicius Gomes
Hi Gustavo,
Quoted 119 lines · Gustavo F. Padovan
Hi Vinicius,
Quoted 115 lines · Vinicius Costa Gomes
This will allow using the crypto subsystem for encrypting data. As SMP (Security Manager Protocol) is implemented almost entirely on the host side and the crypto module already implements the needed methods (AES-128), it makes sense to use it.
This patch also adds a new
Kconfigoption to toggle the SMP support.Signed-off-by Vinicius Costa Gomes <[email protected]>Signed-off-by Anderson Briglia <[email protected]>---
include/net/bluetooth/hci_core.h | 2 ++net/bluetooth/Kconfig| 6 ++++++net/bluetooth/hci_core.c| 22 ++++++++++++++++++++++net/bluetooth/smp.c| 17 +++++++++++++++--4 files changed, 45 insertions(+), 2 deletions(-)include/net/bluetooth/hci_core.h +2
-0@@ -161,6 +161,8 @@ 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;net/bluetooth/Kconfig +1
-0@@ -22,6 +22,7 @@ menuconfig BT BNEP Module (Bluetooth Network Encapsulation Protocol) CMTP Module (CAPI Message Transport Protocol) HIDP Module (Human Interface Device Protocol) + SMP Module (Security Manager Protocol)Say Y here to compile Bluetooth support into the kernel or say M to compile it as module (bluetooth).
net/bluetooth/Kconfig +0
-0@@ -35,11 +36,16 @@ config BT_L2CAPbool "L2CAP protocol support"
depends on BT
select CRC16
+ selectCRYPTO_BLKCIPHER
+ selectCRYPTO_AES
help
L2CAP (Logical Link Control and Adaptation Protocol) provides connection oriented and connection-less data transport. L2CAP support is required for most Bluetooth applications.+ Also included is support for SMP (Security Manager Protocol) which
+ is the security layer on top of LE (Low Energy) links. +
configBT_SCO
bool "SCO links support"
depends on BTnet/bluetooth/hci_core.c +19
-0@@ -42,6 +42,7 @@ #include <linux/notifier.h> #include <linux/rfkill.h> #include <linux/timer.h> +#include <linux/crypto.h> #include <net/sock.h> #include <asm/system.h>@@ -60,6 +61,8 @@ static void hci_notify(struct hci_dev *hdev, int event); static DEFINE_RWLOCK(hci_task_lock); +static int enable_smp; + /* HCI device list */ LIST_HEAD(hci_dev_list); DEFINE_RWLOCK(hci_dev_list_lock);@@ -1077,6 +1080,14 @@ static void hci_cmd_timer(unsigned long arg) tasklet_schedule(&hdev->cmd_task); } +static struct crypto_blkcipher *alloc_cypher (void ) +{ + if (enable_smp) + return crypto_alloc_blkcipher("ecb(aes)", 0, CRYPTO_ALG_ASYNC); + + return ERR_PTR(-ENOTSUPP); +} + /* Register HCI device */ int hci_register_dev(struct hci_dev *hdev) {@@ -1155,6 +1166,11 @@ int hci_register_dev(struct hci_dev *hdev) if (!hdev->workqueue) goto nomem; + hdev->tfm = alloc_cypher(); + 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,@@ -1203,6 +1219,9 @@ 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);Quoted 10 lines
net/bluetooth/hci_core.c static void hci_cmd_task(unsigned long arg) · line 2061
Quoted 8 lines
net/bluetooth/hci_core.c +3
-0if (hdev->rfkill) {@@ -2037,3 +2056,6 @@ static void hci_cmd_task(unsigned long arg) } } } + +module_param (enable_smp, bool,0644 ); +MODULE_PARM_DESC (enable_smp,"Enable SMP support (LE only)" );This all should be obviously inside
smp.cI have a couple of points against it:
1. it's only used for one purpose, it says whether to try or not to allocate the block cypher, which is done during the adapter registration;
Quoted 6 lines
2. If the current way is ok, it would mean that I would need to export another method from
smp.c, that was something that I tried to minimize;3. and my weakest argument, seems that there are other similar uses, for example
enable_mgmt.A similar example here is
enable_ertminsidel2cap_core.c. It's a L2CAP related option and should reside inside L2CAP code.Quoted 1 line
Quoted 5 lines
Quoted 2 lines
But if you think the code will be clearer moving that to
smp.c, will be glad to change.I don't see the point on have it on hci code. SMP and Block cypher has not much to do with HCI. I prefer it on
smp.cGustavo and I were talking on IRC and couldn't come to a solution, so we ask you for some input.
So, just to give a little more context, the problem is that the crypto functions used in SMP depend on the allocation of a block cypher "transform", this allocation must happen during user context.
The current solution is that the allocation is done in
hci_core.cduring the adapter registration, but only when theenable_smpmodule parameter is enabled. When the parameter is disabled the allocation method just returns an invalid pointer and everything happens the same as if the allocation has failed.
Quoted 9 lines
Quoted 6 lines
Gustavo has a preference for an ondemand aproach, for example, using a workqueue for doing the allocation, and trying the allocation just when SMP is going to be used, e.g. when we receive the first SMP message or when some security level is activated for that socket.
Any ideas?
Still no ideas?
We at INdT have some patches based on top of this series. What is the maintainer's opinion about this series? I'm asking it because should be great to know if we are doing the right stuff or we need to change our approach. The number of features and patches that have this series as dependency is growing.
Regards,
Anderson Briglia
Quoted 18 lines
Quoted 10 lines
Quoted 5 lines
--
Gustavo F. Padovan
http://profusion.mobiCheers,
--
Vinicius--
Vinicius
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
INdT - Instituto Nokia de tecnologia +55 2126 1122 http://techblog.briglia.net
Re: [bluetooth-next 04/15] Bluetooth: Add support for using the crypto subsystem
Quoted 20 lines · Anderson Briglia
Hi all,
Quoted 16 lines · Vinicius Costa Gomes
Quoted 15 lines · Vinicius Costa Gomes
Hi Marcel,
Quoted 12 lines · Gustavo F. Padovan
Hi Vinicius,
Quoted 8 lines · Vinicius Gomes
Hi Gustavo,
Quoted 4 lines · Gustavo F. Padovan
Hi Vinicius,
* Vinicius Costa Gomes<[email protected]> [2011-02-21 14:23:51 -0300]:
[...]
Quoted 11 lines
Quoted 5 lines
Quoted 2 lines
Any ideas?
Still no ideas?
We at INdT have some patches based on top of this series. What is the maintainer's opinion about this series? I'm asking it because should be great to know if we are doing the right stuff or we need to change our approach. The number of features and patches that have this series as dependency is growing.
I am also developing patches off of this series and have signed off on their baseline functionality.
Quoted 3 lines
Regards,
Anderson Briglia
Signature · 4 lines
Brian Gix [email protected] Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
Re: [bluetooth-next 04/15] Bluetooth: Add support for using the crypto subsystem
Hi all developers interested on LE,
Quoted 51 lines · Brian Gix
Quoted 27 lines · Anderson Briglia
Hi all,
Quoted 22 lines · Vinicius Costa Gomes
Quoted 20 lines · Vinicius Costa Gomes
Hi Marcel,
Quoted 16 lines · Gustavo F. Padovan
Hi Vinicius,
* Vinicius Gomes<[email protected]> [2011-02-27 21:49:39 -0300]:
Quoted 10 lines
Hi Gustavo,
Quoted 6 lines · Gustavo F. Padovan
Hi Vinicius,
* Vinicius Costa Gomes<[email protected]> [2011-02-21 14:23:51 -0300]:
[...]
Quoted 11 lines
Quoted 5 lines
Quoted 2 lines
Any ideas?
Still no ideas?
We at INdT have some patches based on top of this series. What is the maintainer's opinion about this series? I'm asking it because should be great to know if we are doing the right stuff or we need to change our approach. The number of features and patches that have this series as dependency is growing.
I am also developing patches off of this series and have signed off on their baseline functionality.
Quoted 3 lines
Regards,
Anderson Briglia
Quoted 11 lines
--
Brian Gix
[email protected]
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum --
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Patches not upstream(bluetooth-next) are available here:git://gitorious.org/bluetooth-next/for-upstream.git
Contains patches for SM just works method, advertising cache and MTU.
BR,
Claudio
Re: [bluetooth-next 04/15] Bluetooth: Add support for using the crypto subsystem
Quoted 66 lines · Claudio Takahasi
Hi all developers interested on LE,
Quoted 51 lines · Brian Gix
Quoted 27 lines · Anderson Briglia
Hi all,
Quoted 22 lines · Vinicius Costa Gomes
Quoted 20 lines · Vinicius Costa Gomes
Hi Marcel,
Quoted 16 lines · Gustavo F. Padovan
Hi Vinicius,
* Vinicius Gomes<[email protected]> [2011-02-27 21:49:39
-0300]:Quoted 10 lines
Hi Gustavo,
Quoted 6 lines · Gustavo F. Padovan
Hi Vinicius,
* Vinicius Costa Gomes<[email protected]> [2011-02-21
14:23:51 -0300]:[...]
Quoted 11 lines
Quoted 5 lines
Quoted 2 lines
Any ideas?
Still no ideas?
We at INdT have some patches based on top of this series. What is the maintainer's opinion about this series? I'm asking it because should be great to know if we are doing the right stuff or we need to change our approach. The number of features and patches that have this series as dependency is growing.
I am also developing patches off of this series and have signed off on their baseline functionality.
Quoted 3 lines
Regards,
Anderson Briglia
Quoted 11 lines
--
Brian Gix
[email protected]
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum --
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines
Patches not upstream(bluetooth-next) are available here:
git://gitorious.org/bluetooth-next/for-upstream.gitContains patches for SM just works method, advertising cache and MTU.
Are these rebased off of bluetooth-next on kernel.org?
Quoted 2 lines
BR,
Claudio
Signature · 4 lines
Brian Gix [email protected] Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
Re: [bluetooth-next 04/15] Bluetooth: Add support for using the crypto subsystem
Quoted 3 lines · Brian Gix
Quoted 2 lines · Claudio Takahasi
Hi all developers interested on LE,
[ ... ]
Quoted 8 lines
Quoted 5 lines
Patches not upstream(bluetooth-next) are available here:
git://gitorious.org/bluetooth-next/for-upstream.gitContains patches for SM just works method, advertising cache and MTU.
Are these rebased off of bluetooth-next on kernel.org?
Now they are.
I also pushed the patches that add support for storing (and using) LTKs to this repository. It needs a userspace that supports this[1].
I am not sending them for proper review yet, because they depend strongly on the first SMP patches. But comments are welcome.
Quoted 14 lines
Quoted 3 lines
BR,
ClaudioSignature · 8 lines
Brian Gix [email protected] Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum -- To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Cheers,
Signature · 3 lines
Vinicius [1] git://gitorious.org/~vcgomes/bluez/vcgomes-bluez.git (branch mgmt)
PATCH 5/15 Bluetooth: LE SMP Cryptoolbox functions
In reply to Vinicius Costa GomesFrom: Anderson Briglia <[email protected]>
This patch implements SMP crypto functions called ah, c1, s1 and e. It also implements auxiliary functions. All These functions are needed for SMP keys generation.
--- net/bluetooth/smp.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 122 insertions(+), 0 deletions(-)
net/bluetooth/smp.c +122 -0
@@ -24,6 +24,128 @@#include <net/bluetooth/hci_core.h> #include <net/bluetooth/l2cap.h> #include <net/bluetooth/smp.h> +#include <linux/crypto.h> +#include <crypto/b128ops.h> + +static inline void swap128 (u8 src[16 ],u8 dst[16 ]) +{ +int i; +for (i =0 ; i <16 ; i++) + dst[15 - i] = src[i]; +} + +static inline void swap56 (u8 src[7 ],u8 dst[7 ]) +{ +int i; +for (i =0 ; i <7 ; i++) + dst[6 - i] = src[i]; +} + +static int smp_e (struct crypto_blkcipher *tfm,const u8 *k,u8 *r) +{ +struct blkcipher_desc desc; +struct scatterlist sg; +int err, iv_len; +unsigned char iv[128 ]; + +if (tfm ==NULL ) { +BT_ERR ("tfm %p" , tfm); +return -EINVAL ; + } + + desc.tfm = tfm; + desc.flags =0 ; + + err =crypto_blkcipher_setkey (tfm, k,16 ); +if (err) { +BT_ERR ("cipher setkey failed: %d" , err); +return err; + } + +sg_init_one (&sg, r,16 ); + + iv_len =crypto_blkcipher_ivsize (tfm); +if (iv_len) { +memset (&iv,0xff , iv_len); +crypto_blkcipher_set_iv (tfm, iv, iv_len); + } + + err =crypto_blkcipher_encrypt (&desc, &sg, &sg,16 ); +if (err) +BT_ERR ("Encrypt data error %d" , err); + +return err; +} + +static int smp_c1 (struct crypto_blkcipher *tfm,u8 k[16 ],u8 r[16 ], +u8 preq[7 ],u8 pres[7 ],u8 _iat,bdaddr_t *ia, +u8 _rat,bdaddr_t *ra,u8 res[16 ]) +{ +u8 p1[16 ], p2[16 ], pair[7 ]; +bdaddr_t addr; +int err; + +/* p1 = pres || preq || _rat || _iat */ +memset (p1,0 ,16 ); +swap56 (pres, pair); + +memcpy (p1, pair,7 ); +swap56 (preq, pair); + +memcpy (p1 +7 , pair,7 ); + *(p1 +14 ) = _rat; + *(p1 +15 ) = _iat; + +/* p2 = padding || ia || ra */ +memset (p2,0 ,16 ); +baswap (&addr, ia); +memcpy (p2 +4 , &addr,6 ); +baswap (&addr, ra); +memcpy (p2 +10 , &addr,6 ); + +/* res = r XOR p1 */ +u128_xor ((u128 *) res, (u128 *) r, (u128 *) p1); + +/* res = e(k, res) */ + err =smp_e (tfm, k, res); +if (err) { +BT_ERR ("Encrypt data error" ); +return err; + } + +/* res = res XOR p2 */ +u128_xor ((u128 *) res, (u128 *) res, (u128 *) p2); + +/* res = e(k, res) */ + err =smp_e (tfm, k, res); +if (err) +BT_ERR ("Encrypt data error" ); + +return err; +} + +static int smp_s1 (struct crypto_blkcipher *tfm,u8 k[16 ], +u8 r1[16 ],u8 r2[16 ],u8 _r[16 ]) +{ +int err; + +/* Just least significant octets from r1 and r2 are considered */ +memcpy (_r, r1 +8 ,8 ); +memcpy (_r +8 , r2 +8 ,8 ); + + err =smp_e (tfm, k, _r); +if (err) +BT_ERR ("Encrypt data error" ); + +return err; +} + +static int smp_rand (u8 *buf) +{ +get_random_bytes (buf,16 ); + +return 0 ; +}static struct sk_buff *smp_build_cmd (struct l2cap_conn *conn,u8 code,u16 dlen,void *data)
Signature · 1 line
1.7.4.1
PATCH 6/15 Bluetooth: Add SMP confirmation structs
In reply to Vinicius Costa GomesFrom: Anderson Briglia <[email protected]>
This patch adds initial support for verifying the confirmation value that the remote side has sent.
--- include/net/bluetooth/l2cap.h | 5 +++++ net/bluetooth/smp.c | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)
include/net/bluetooth/l2cap.h +5 -0
@@ -307,6 +307,11 @@ 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 */ +struct l2cap_chan_list chan_list; };
net/bluetooth/smp.c +17 -0
@@ -192,6 +192,8 @@ static void smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)BT_DBG ("conn %p" , conn); + conn->preq[0 ] =SMP_CMD_PAIRING_REQ ; +memcpy (&conn->preq[1 ], rp,sizeof (*rp));skb_pull (skb,sizeof (*rp)); rp->io_capability =0x00 ;
@@ -201,17 +203,25 @@ static void smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb) rp->resp_key_dist =0x00 ; rp->auth_req &= (SMP_AUTH_BONDING |SMP_AUTH_MITM ); + conn->prsp[0 ] =SMP_CMD_PAIRING_RSP ; +memcpy (&conn->prsp[1 ], rp,sizeof (*rp)); +smp_send_cmd (conn,SMP_CMD_PAIRING_RSP ,sizeof (*rp), rp); }static void smp_cmd_pairing_rsp (struct l2cap_conn *conn,struct sk_buff *skb) { +struct smp_cmd_pairing *rp = (void *) skb->data;struct smp_cmd_pairing_confirm cp;BT_DBG ("conn %p" , conn);memset (&cp,0 ,sizeof (cp)); + conn->prsp[0 ] =SMP_CMD_PAIRING_RSP ; +memcpy (&conn->prsp[1 ], rp,sizeof (*rp)); +skb_pull (skb,sizeof (*rp)); +smp_send_cmd (conn,SMP_CMD_PAIRING_CONFIRM ,sizeof (cp), &cp); }
@@ -270,6 +280,9 @@ static void smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) cp.resp_key_dist =0x00 ; cp.auth_req = rp->auth_req & (SMP_AUTH_BONDING |SMP_AUTH_MITM ); + conn->preq[0 ] =SMP_CMD_PAIRING_REQ ; +memcpy (&conn->preq[1 ], &cp,sizeof (cp)); +smp_send_cmd (conn,SMP_CMD_PAIRING_REQ ,sizeof (cp), &cp); }
@@ -306,6 +319,10 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level) cp.init_key_dist =0x00 ; cp.resp_key_dist =0x00 ; cp.auth_req = authreq; + + conn->preq[0 ] =SMP_CMD_PAIRING_REQ ; +memcpy (&conn->preq[1 ], &cp,sizeof (cp)); +smp_send_cmd (conn,SMP_CMD_PAIRING_REQ ,sizeof (cp), &cp); }else {struct smp_cmd_security_req cp;
Signature · 1 line
1.7.4.1
PATCH 7/15 Bluetooth: Add SMP confirmation checks methods
In reply to Vinicius Costa GomesFrom: Anderson Briglia <[email protected]>
This patch includes support for generating and sending the random value used to produce the confirmation value.
--- include/net/bluetooth/l2cap.h | 1 + net/bluetooth/smp.c | 92 ++++++++++++++++++++++++++++++++++------ 2 files changed, 79 insertions(+), 14 deletions(-)
include/net/bluetooth/l2cap.h +1 -0
@@ -311,6 +311,7 @@ struct l2cap_conn {__u8 prsp[7 ];/* SMP Pairing Response */ __u8 prnd[16 ];/* SMP Pairing Random */ __u8 pcnf[16 ];/* SMP Pairing Confirm */ +__u8 tk[16 ];/* SMP Temporary Key */ struct l2cap_chan_list chan_list; };
net/bluetooth/smp.c +78 -14
137 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 8/15 Bluetooth: Minor fix in SMP methods
In reply to Vinicius Costa GomesFrom: Anderson Briglia <[email protected]>
Minor fix in smp_conn_security function.
--- net/bluetooth/smp.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
net/bluetooth/smp.c +5 -4
@@ -352,12 +352,13 @@ static void smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)int smp_conn_security (struct l2cap_conn *conn,__u8 sec_level) { +struct hci_conn *hcon = conn->hcon;__u8 authreq; -BT_DBG ("conn %p hcon %p level 0x%2.2x" , conn, conn->hcon, sec_level); +BT_DBG ("conn %p hcon %p level 0x%2.2x" , conn, hcon, sec_level); -if (IS_ERR (conn->hcon->hdev->tfm)) -return PTR_ERR (conn->hcon->hdev->tfm); +if (IS_ERR (hcon->hdev->tfm)) +return PTR_ERR (hcon->hdev->tfm);switch (sec_level) {case BT_SECURITY_MEDIUM :
@@ -375,7 +376,7 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level)return 1 ; } -if (conn->hcon->link_mode &HCI_LM_MASTER ) { +if (hcon->link_mode &HCI_LM_MASTER ) {struct smp_cmd_pairing cp; cp.io_capability =0x00 ; cp.oob_flag =0x00 ;
Signature · 1 line
1.7.4.1
PATCH 9/15 Bluetooth: Add support for LE Start Encryption
In reply to Vinicius Costa GomesThis adds support for starting SMP Phase 2 Encryption, when the initial SMP negotiation is successful. This adds the LE Start Encryption and LE Long Term Key Request commands and related events.
--- include/net/bluetooth/hci.h | 34 +++++++++++++++++++ include/net/bluetooth/hci_core.h | 5 +++ net/bluetooth/hci_conn.c | 46 ++++++++++++++++++++++++++ net/bluetooth/hci_event.c | 67 ++++++++++++++++++++++++++++++++++++++ net/bluetooth/smp.c | 9 ++++- 5 files changed, 160 insertions(+), 1 deletions(-)
include/net/bluetooth/hci.h +34 -0
@@ -688,6 +688,33 @@ struct hci_cp_le_conn_update {__le16 max_ce_len; } __packed; +#define HCI_OP_LE_START_ENC 0x2019 +struct hci_cp_le_start_enc { +__le16 handle; +__u8 rand[8 ]; +__le16 ediv; +__u8 ltk[16 ]; +} __packed; + +#define HCI_OP_LE_LTK_REPLY 0x201a +struct hci_cp_le_ltk_reply { +__le16 handle; +__u8 ltk[16 ]; +} __packed; +struct hci_rp_le_ltk_reply { +__u8 status; +__le16 handle; +} __packed; + +#define HCI_OP_LE_LTK_NEG_REPLY 0x201b +struct hci_cp_le_ltk_neg_reply { +__le16 handle; +} __packed; +struct hci_rp_le_ltk_neg_reply { +__u8 status; +__le16 handle; +} __packed; +/* ---- HCI Events ---- */ #define HCI_EV_INQUIRY_COMPLETE 0x01
@@ -967,6 +994,13 @@ struct hci_ev_le_conn_complete {__u8 clk_accurancy; } __packed; +#define HCI_EV_LE_LTK_REQ 0x05 +struct hci_ev_le_ltk_req { +__le16 handle; +__u8 random[8 ]; +__le16 ediv; +} __packed; +/* Internal events generated by Bluetooth stack */ #define HCI_EV_STACK_INTERNAL 0xfdstruct hci_ev_stack_internal {
include/net/bluetooth/hci_core.h +5 -0
@@ -226,6 +226,7 @@ struct hci_conn {__u8 power_save;__u16 disc_timeout;unsigned long pend; +__u8 ltk[16 ];__u8 remote_cap;__u8 remote_oob;
@@ -781,4 +782,8 @@ void hci_req_complete(struct hci_dev *hdev, __u16 cmd, int result);void hci_le_conn_update (struct hci_conn *conn,u16 min,u16 max,u16 latency,u16 to_multiplier); +void hci_le_start_enc (struct hci_conn *conn,u8 ltk[16 ]); +void hci_le_ltk_reply (struct hci_conn *conn,u8 ltk[16 ]); +void hci_le_ltk_neg_reply (struct hci_conn *conn); +#endif /* __HCI_CORE_H */
net/bluetooth/hci_conn.c +46 -0
52 lines not on this page · raw message
net/bluetooth/hci_event.c +67 -0
103 lines not on this page · raw message
net/bluetooth/smp.c +8 -1
@@ -280,13 +280,16 @@ static void smp_cmd_pairing_confirm(struct l2cap_conn *conn, struct sk_buff *skbstatic void smp_cmd_pairing_random (struct l2cap_conn *conn,struct sk_buff *skb) { -struct crypto_blkcipher *tfm = conn->hcon->hdev->tfm; +struct hci_conn *hcon = conn->hcon; +struct crypto_blkcipher *tfm = hcon->hdev->tfm;int ret;u8 key[16 ], res[16 ], random[16 ], confirm[16 ], buf[128 ];swap128 (skb->data, random);skb_pull (skb,sizeof (random)); +memset (hcon->ltk,0 ,sizeof (hcon->ltk)); +if (conn->hcon->out) ret =smp_c1 (tfm, conn->tk, random, conn->preq, conn->prsp,0 , conn->src,0 , conn->dst, res);
@@ -311,6 +314,9 @@ static void smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)if (conn->hcon->out) {smp_s1 (tfm, conn->tk, random, conn->prnd, key); +swap128 (key, hcon->ltk); + +hci_le_start_enc (hcon, hcon->ltk);hex_dump_to_buffer (key,sizeof (key),16 ,1 , buf,sizeof (buf),0 );BT_DBG ("key %s" , buf);
@@ -321,6 +327,7 @@ static void smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)smp_send_cmd (conn,SMP_CMD_PAIRING_RANDOM ,sizeof (r), r);smp_s1 (tfm, conn->tk, conn->prnd, random, key); +swap128 (key, hcon->ltk);hex_dump_to_buffer (key,sizeof (key),16 ,1 , buf,sizeof (buf),0 );BT_DBG ("key %s" , buf);
Signature · 1 line
1.7.4.1
PATCH 1/1 Bluetooth: Add support for LE Start Encryption
This adds support for starting SMP Phase 2 Encryption, when the initial SMP negotiation is successful. This adds the LE Start Encryption and LE Long Term Key Request commands and related events.
---
Now this should apply cleanly after Johan's patches now in bluetooth-next.
include/net/bluetooth/hci.h | 34 +++++++++++++++++++ include/net/bluetooth/hci_core.h | 5 +++ net/bluetooth/hci_conn.c | 46 ++++++++++++++++++++++++++ net/bluetooth/hci_event.c | 67 ++++++++++++++++++++++++++++++++++++++ net/bluetooth/smp.c | 9 ++++- 5 files changed, 160 insertions(+), 1 deletions(-)
include/net/bluetooth/hci.h +34 -0
@@ -699,6 +699,33 @@ struct hci_cp_le_conn_update {__le16 max_ce_len; } __packed; +#define HCI_OP_LE_START_ENC 0x2019 +struct hci_cp_le_start_enc { +__le16 handle; +__u8 rand[8 ]; +__le16 ediv; +__u8 ltk[16 ]; +} __packed; + +#define HCI_OP_LE_LTK_REPLY 0x201a +struct hci_cp_le_ltk_reply { +__le16 handle; +__u8 ltk[16 ]; +} __packed; +struct hci_rp_le_ltk_reply { +__u8 status; +__le16 handle; +} __packed; + +#define HCI_OP_LE_LTK_NEG_REPLY 0x201b +struct hci_cp_le_ltk_neg_reply { +__le16 handle; +} __packed; +struct hci_rp_le_ltk_neg_reply { +__u8 status; +__le16 handle; +} __packed; +/* ---- HCI Events ---- */ #define HCI_EV_INQUIRY_COMPLETE 0x01
@@ -984,6 +1011,13 @@ struct hci_ev_le_conn_complete {__u8 clk_accurancy; } __packed; +#define HCI_EV_LE_LTK_REQ 0x05 +struct hci_ev_le_ltk_req { +__le16 handle; +__u8 random[8 ]; +__le16 ediv; +} __packed; +/* Internal events generated by Bluetooth stack */ #define HCI_EV_STACK_INTERNAL 0xfdstruct hci_ev_stack_internal {
include/net/bluetooth/hci_core.h +5 -0
@@ -226,6 +226,7 @@ struct hci_conn {__u8 power_save;__u16 disc_timeout;unsigned long pend; +__u8 ltk[16 ];__u8 remote_cap;__u8 remote_oob;
@@ -802,4 +803,8 @@ void hci_req_complete(struct hci_dev *hdev, __u16 cmd, int result);void hci_le_conn_update (struct hci_conn *conn,u16 min,u16 max,u16 latency,u16 to_multiplier); +void hci_le_start_enc (struct hci_conn *conn,u8 ltk[16 ]); +void hci_le_ltk_reply (struct hci_conn *conn,u8 ltk[16 ]); +void hci_le_ltk_neg_reply (struct hci_conn *conn); +#endif /* __HCI_CORE_H */
net/bluetooth/hci_conn.c +46 -0
52 lines not on this page · raw message
net/bluetooth/hci_event.c +67 -0
103 lines not on this page · raw message
net/bluetooth/smp.c +8 -1
@@ -280,13 +280,16 @@ static void smp_cmd_pairing_confirm(struct l2cap_conn *conn, struct sk_buff *skbstatic void smp_cmd_pairing_random (struct l2cap_conn *conn,struct sk_buff *skb) { -struct crypto_blkcipher *tfm = conn->hcon->hdev->tfm; +struct hci_conn *hcon = conn->hcon; +struct crypto_blkcipher *tfm = hcon->hdev->tfm;int ret;u8 key[16 ], res[16 ], random[16 ], confirm[16 ], buf[128 ];swap128 (skb->data, random);skb_pull (skb,sizeof (random)); +memset (hcon->ltk,0 ,sizeof (hcon->ltk)); +if (conn->hcon->out) ret =smp_c1 (tfm, conn->tk, random, conn->preq, conn->prsp,0 , conn->src,0 , conn->dst, res);
@@ -311,6 +314,9 @@ static void smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)if (conn->hcon->out) {smp_s1 (tfm, conn->tk, random, conn->prnd, key); +swap128 (key, hcon->ltk); + +hci_le_start_enc (hcon, hcon->ltk);hex_dump_to_buffer (key,sizeof (key),16 ,1 , buf,sizeof (buf),0 );BT_DBG ("key %s" , buf);
@@ -321,6 +327,7 @@ static void smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)smp_send_cmd (conn,SMP_CMD_PAIRING_RANDOM ,sizeof (r), r);smp_s1 (tfm, conn->tk, conn->prnd, random, key); +swap128 (key, hcon->ltk);hex_dump_to_buffer (key,sizeof (key),16 ,1 , buf,sizeof (buf),0 );BT_DBG ("key %s" , buf);
Signature · 1 line
1.7.4.1
PATCH 10/15 Bluetooth: Add support for resuming socket when SMP is finished
In reply to Vinicius Costa GomesThis adds support for resuming the user space traffic when SMP negotiation is complete.
--- net/bluetooth/l2cap_core.c | 61 ++++++++++++++++++++++--------------------- net/bluetooth/l2cap_sock.c | 17 ++++++++++++ net/bluetooth/smp.c | 40 ++++++++++++++++++++-------- 3 files changed, 76 insertions(+), 42 deletions(-)
net/bluetooth/l2cap_core.c +31 -30
@@ -666,6 +666,22 @@ clean:bh_unlock_sock (parent); } +static void l2cap_chan_ready (struct sock *sk) +{ +struct sock *parent =bt_sk (sk)->parent; + +BT_DBG ("sk %p, parent %p" , sk, parent); + +l2cap_pi (sk)->conf_state =0 ; +l2cap_sock_clear_timer (sk); + + sk->sk_state =BT_CONNECTED ; + sk->sk_state_change (sk); + +if (parent) + parent->sk_data_ready (parent,0 ); +} +static void l2cap_conn_ready (struct l2cap_conn *conn) {struct l2cap_chan_list *l = &conn->chan_list;
@@ -681,15 +697,11 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)for (sk = l->head; sk; sk =l2cap_pi (sk)->next_c) {bh_lock_sock (sk); -if (conn->hcon->type ==LE_LINK ) { -l2cap_sock_clear_timer (sk); - sk->sk_state =BT_CONNECTED ; - sk->sk_state_change (sk); +if (l2cap_pi (sk)->scid ==L2CAP_CID_LE_DATA ) {if (smp_conn_security (conn,l2cap_pi (sk)->sec_level)) -BT_DBG ("Insufficient security" ); - } +l2cap_chan_ready (sk); -if (sk->sk_type !=SOCK_SEQPACKET && + }else if (sk->sk_type !=SOCK_SEQPACKET && sk->sk_type !=SOCK_STREAM ) {l2cap_sock_clear_timer (sk); sk->sk_state =BT_CONNECTED ;
@@ -1360,29 +1372,6 @@ int l2cap_sar_segment_sdu(struct sock *sk, struct msghdr *msg, size_t len)return size; } -static void l2cap_chan_ready (struct sock *sk) -{ -struct sock *parent =bt_sk (sk)->parent; - -BT_DBG ("sk %p, parent %p" , sk, parent); - -l2cap_pi (sk)->conf_state =0 ; -l2cap_sock_clear_timer (sk); - -if (!parent) { -/* Outgoing channel. -* Wake up socket sleeping on connect. -*/ - sk->sk_state =BT_CONNECTED ; - sk->sk_state_change (sk); - }else { -/* Incoming channel. -* Wake up socket sleeping on accept. -*/ - parent->sk_data_ready (parent,0 ); - } -} -/* Copy frame to all raw sockets on that connection */ static void l2cap_raw_recv (struct l2cap_conn *conn,struct sk_buff *skb) {
@@ -3800,6 +3789,18 @@ static int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)for (sk = l->head; sk; sk =l2cap_pi (sk)->next_c) {bh_lock_sock (sk); +BT_DBG ("sk->scid %d" ,l2cap_pi (sk)->scid); + +if (l2cap_pi (sk)->scid ==L2CAP_CID_LE_DATA ) { +if (!status && encrypt) { +l2cap_pi (sk)->sec_level = hcon->sec_level; +l2cap_chan_ready (sk); + } + +bh_unlock_sock (sk); +continue ; + } +if (l2cap_pi (sk)->conf_state &L2CAP_CONF_CONNECT_PEND ) {bh_unlock_sock (sk);continue ;
net/bluetooth/l2cap_sock.c +17 -0
@@ -29,6 +29,7 @@#include <net/bluetooth/bluetooth.h> #include <net/bluetooth/hci_core.h> #include <net/bluetooth/l2cap.h> +#include <net/bluetooth/smp.h> /* ---- L2CAP timers ---- */ static void l2cap_sock_timeout (unsigned long arg)
@@ -614,6 +615,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch {struct sock *sk = sock->sk;struct bt_security sec; +struct l2cap_conn *conn;int len, err =0 ;u32 opt;
@@ -650,6 +652,21 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch }l2cap_pi (sk)->sec_level = sec.level; + + conn =l2cap_pi (sk)->conn; +if (conn &&l2cap_pi (sk)->scid ==L2CAP_CID_LE_DATA ) { +if (!conn->hcon->out) { + err = -EINVAL ; +break ; + } + +if (!smp_conn_security (conn, sec.level)) { + err = -EINVAL ; +break ; + } + + sk->sk_state =BT_CONFIG ; + }break ;case BT_DEFER_SETUP :
net/bluetooth/smp.c +28 -12
@@ -338,9 +338,13 @@ static void smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) {struct smp_cmd_security_req *rp = (void *) skb->data;struct smp_cmd_pairing cp; +struct hci_conn *hcon = conn->hcon;BT_DBG ("conn %p" , conn); +if (test_bit (HCI_CONN_ENCRYPT_PEND , &hcon->pend)) +return ; +skb_pull (skb,sizeof (*rp));memset (&cp,0 ,sizeof (cp));
@@ -355,6 +359,20 @@ static void smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)memcpy (&conn->preq[1 ], &cp,sizeof (cp));smp_send_cmd (conn,SMP_CMD_PAIRING_REQ ,sizeof (cp), &cp); + +set_bit (HCI_CONN_ENCRYPT_PEND , &hcon->pend); +} + +static __u8 seclevel_to_authreq (__u8 level) +{ +switch (level) { +case BT_SECURITY_HIGH : +/* For now we don't support bonding */ +return SMP_AUTH_MITM ; + +default : +return SMP_AUTH_NONE ; + } }int smp_conn_security (struct l2cap_conn *conn,__u8 sec_level)
@@ -367,21 +385,16 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level)if (IS_ERR (hcon->hdev->tfm))return PTR_ERR (hcon->hdev->tfm); -switch (sec_level) { -case BT_SECURITY_MEDIUM : -/* Encrypted, no MITM protection */ - authreq =HCI_AT_NO_BONDING_MITM ; -break ; +if (test_bit (HCI_CONN_ENCRYPT_PEND , &hcon->pend)) +return -EINPROGRESS ; -case BT_SECURITY_HIGH : -/* Bonding, MITM protection */ - authreq =HCI_AT_GENERAL_BONDING_MITM ; -break ; +if (sec_level ==BT_SECURITY_LOW ) +return 1 ; -case BT_SECURITY_LOW : -default : +if (hcon->sec_level > sec_level)return 1 ; - } + + authreq =seclevel_to_authreq (sec_level);if (hcon->link_mode &HCI_LM_MASTER ) {struct smp_cmd_pairing cp;
@@ -402,6 +415,9 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level)smp_send_cmd (conn,SMP_CMD_SECURITY_REQ ,sizeof (cp), &cp); } + hcon->pending_sec_level = sec_level; +set_bit (HCI_CONN_ENCRYPT_PEND , &hcon->pend); +return 0 ; }
Signature · 1 line
1.7.4.1
PATCH 11/15 Bluetooth: Fix initial security level of LE links
In reply to Vinicius Costa GomesAs the default security level (BT_SECURITY_SDP) doesn't make sense for LE links, initialize LE links with something that makes sense.
--- net/bluetooth/hci_conn.c | 1 + net/bluetooth/hci_event.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
net/bluetooth/hci_conn.c +1 -0
@@ -53,6 +53,7 @@ static void hci_le_connect(struct hci_conn *conn) conn->state =BT_CONNECT ; conn->out =1 ; conn->link_mode |=HCI_LM_MASTER ; + conn->sec_level =BT_SECURITY_LOW ;memset (&cp,0 ,sizeof (cp)); cp.scan_interval =cpu_to_le16 (0x0004 );
net/bluetooth/hci_event.c +1 -0
@@ -2461,6 +2461,7 @@ static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff goto unlock; } + conn->sec_level =BT_SECURITY_LOW ; conn->handle =__le16_to_cpu (ev->handle); conn->state =BT_CONNECTED ;
Signature · 1 line
1.7.4.1
PATCH 12/15 Bluetooth: Update the security level when link is encrypted
In reply to Vinicius Costa GomesIf the pending security level is greater than the current security level and the link is now encrypted, we should update the link security level.
This is only useful for LE links, when the only event generated when SMP is sucessful in the Encrypt Change event.
--- include/net/bluetooth/hci_core.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
include/net/bluetooth/hci_core.h +3 -0
@@ -679,6 +679,9 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status, __u8 encrif (conn->sec_level ==BT_SECURITY_SDP ) conn->sec_level =BT_SECURITY_LOW ; +if (conn->pending_sec_level > conn->sec_level) + conn->sec_level = conn->pending_sec_level; +hci_proto_encrypt_cfm (conn, status, encrypt);read_lock_bh (&hci_cb_list_lock);
Signature · 1 line
1.7.4.1
PATCH 13/15 Bluetooth: Add support for Pairing features exchange
In reply to Vinicius Costa GomesThis patch implements a simple version of the SMP Pairing Features exchange procedure (Vol. 3 Part H, Section 2.3.5.1).
For now, everything that would cause a Pairing Method different of Just Works to be chosen is rejected.
--- net/bluetooth/hci_event.c | 1 + net/bluetooth/smp.c | 115 ++++++++++++++++++++++++-------------------- 2 files changed, 64 insertions(+), 52 deletions(-)
net/bluetooth/hci_event.c +1 -0
@@ -1510,6 +1510,7 @@ static inline void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff */* Encryption implies authentication */ conn->link_mode |=HCI_LM_AUTH ; conn->link_mode |=HCI_LM_ENCRYPT ; + conn->sec_level = conn->pending_sec_level; }else conn->link_mode &= ~HCI_LM_ENCRYPT ; }
net/bluetooth/smp.c +63 -52
241 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 14/15 Bluetooth: Add support for SMP timeout
In reply to Vinicius Costa GomesThis patch adds support for disconnecting the link when SMP procedure takes more than 30 seconds.
SMP begins when either the Pairing Request command is sent or the Pairing Response is received, and it ends when the link is encrypted (or terminated). Vol 3, Part H Section 3.4.
--- include/net/bluetooth/l2cap.h | 2 + net/bluetooth/l2cap_core.c | 70 ++++++++++++++++++++++++---------------- net/bluetooth/smp.c | 14 ++++++++ 3 files changed, 58 insertions(+), 28 deletions(-)
include/net/bluetooth/l2cap.h +2 -0
@@ -313,6 +313,8 @@ struct l2cap_conn {__u8 pcnf[16 ];/* SMP Pairing Confirm */ __u8 tk[16 ];/* SMP Temporary Key */ +struct timer_list security_timer; +struct l2cap_chan_list chan_list; };
net/bluetooth/l2cap_core.c +42 -28
100 lines not on this page · raw message
net/bluetooth/smp.c +14 -0
@@ -27,6 +27,8 @@#include <linux/crypto.h> #include <crypto/b128ops.h> +#define SMP_TIMEOUT 30000/* 30 seconds */ +static inline void swap128 (u8 src[16 ],u8 dst[16 ]) {int i;
@@ -232,6 +234,9 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)smp_send_cmd (conn,SMP_CMD_PAIRING_RSP ,sizeof (*rp), rp); +mod_timer (&conn->security_timer, jiffies + +msecs_to_jiffies (SMP_TIMEOUT )); +return 0 ; }
@@ -306,6 +311,9 @@ static u8 smp_cmd_pairing_confirm(struct l2cap_conn *conn, struct sk_buff *skb)smp_send_cmd (conn,SMP_CMD_PAIRING_CONFIRM ,sizeof (cp), &cp); } +mod_timer (&conn->security_timer, jiffies + +msecs_to_jiffies (SMP_TIMEOUT )); +return 0 ; }
@@ -384,6 +392,9 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)smp_send_cmd (conn,SMP_CMD_PAIRING_REQ ,sizeof (cp), &cp); +mod_timer (&conn->security_timer, jiffies + +msecs_to_jiffies (SMP_TIMEOUT )); +set_bit (HCI_CONN_ENCRYPT_PEND , &hcon->pend);return 0 ;
@@ -417,6 +428,9 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level) conn->preq[0 ] =SMP_CMD_PAIRING_REQ ;memcpy (&conn->preq[1 ], &cp,sizeof (cp)); +mod_timer (&conn->security_timer, jiffies + +msecs_to_jiffies (SMP_TIMEOUT )); +smp_send_cmd (conn,SMP_CMD_PAIRING_REQ ,sizeof (cp), &cp); }else {struct smp_cmd_security_req cp;
Signature · 1 line
1.7.4.1
PATCH 15/15 Bluetooth: Add key size checks for SMP
In reply to Vinicius Costa GomesThis patch implements a check in smp cmd pairing request and pairing response to verify if encryption key maximum size is compatible in both slave and master when SMP Pairing is requested. Keys are also masked to the correct negotiated size.
--- include/net/bluetooth/l2cap.h | 1 + include/net/bluetooth/smp.h | 3 ++ net/bluetooth/smp.c | 54 +++++++++++++++++++++++++++++++---------- 3 files changed, 45 insertions(+), 13 deletions(-)
include/net/bluetooth/l2cap.h +1 -0
@@ -312,6 +312,7 @@ struct l2cap_conn {__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;
include/net/bluetooth/smp.h +3 -0
@@ -112,6 +112,9 @@ struct smp_cmd_security_req {#define SMP_UNSPECIFIED 0x08#define SMP_REPEATED_ATTEMPTS 0x09 +#define SMP_MIN_ENC_KEY_SIZE 7 +#define SMP_MAX_ENC_KEY_SIZE 16 +/* 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/smp.c +41 -13
112 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Hi Gustavo, Vinicius,
I would like to add my support for promoting these LE Security Manager patches into the bluetooth-next tip.
Quoted 54 lines · Vinicius Costa Gomes
Hi,
This patch series implement the Just Works SMP procedures for LE links.
These patches can also be reached from here[1].
Cheers,
--
Vinicius[1] http://git.infradead.org/users/vcgomes/linux-2.6.git (for-next branch)
Anderson Briglia (7):
Bluetooth: Implement the first SMP commands
Bluetooth: Start SMP procedure
Bluetooth: simple SMP pairing negotiation
Bluetooth: LE SMP Cryptoolbox functions
Bluetooth: Add SMP confirmation structs
Bluetooth: Add SMP confirmation checks methods
Bluetooth: Minor fix in SMP methodsVinicius Costa Gomes (8):
Bluetooth: Add support for using the crypto subsystem
Bluetooth: Add support for LE Start Encryption
Bluetooth: Add support for resuming socket when SMP is finished
Bluetooth: Fix initial security level of LE links
Bluetooth: Update the security level when link is encrypted
Bluetooth: Add support for Pairing features exchange
Bluetooth: Add support for SMP timeout
Bluetooth: Add key size checks for SMPinclude/net/bluetooth/hci.h | 34 +++ include/net/bluetooth/hci_core.h | 10 + include/net/bluetooth/l2cap.h | 9 + include/net/bluetooth/smp.h | 46 ++++ net/bluetooth/Kconfig | 6 + net/bluetooth/Makefile | 2 +- net/bluetooth/hci_conn.c | 47 ++++ net/bluetooth/hci_core.c | 22 ++ net/bluetooth/hci_event.c | 69 +++++ net/bluetooth/l2cap_core.c | 137 ++++++---- net/bluetooth/l2cap_sock.c | 17 ++ net/bluetooth/smp.c | 535 ++++++++++++++++++++++++++++++++++++++ 12 files changed, 876 insertions(+), 58 deletions(-)create mode 100644
net/bluetooth/smp.c--
1.7.4.1--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 4 lines
Brian Gix [email protected] Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
Hi,
Quoted 5 lines · Brian Gix
Hi Gustavo, Vinicius,
I would like to add my support for promoting these LE Security Manager patches into the bluetooth-next tip.
I would like to add my support as well :-)
On the other hand I did some (minor) improvements on the error handling. It can be found on my personal repository[1].
As the difference is just a couple of lines, I am not spammig this list again.
Quoted 8 lines · Vinicius Costa Gomes
Quoted 6 lines
Hi,
This patch series implement the Just Works SMP procedures for LE links.
These patches can also be reached from here[1].
[ ... ]
Quoted 6 lines
Signature · 5 lines
-- Brian Gix [email protected] Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
Signature · 5 lines
Vinicius
[1] git://git.infradead.org/users/vcgomes/linux-2.6.git for-next
http://git.infradead.org/users/vcgomes/linux-2.6.git (for-next branch)
http://gitorious.org/bluetooth-next/bluetooth-next (mirror)