Skip to contentSkip to conversation

Bluetooth: Add MITM protection to SMP

PATCH In review Brian Gix 3 participants 12 messages Nov 12, 2011

Subsystems (2)
lore
Share & tools
lore

Brian Gix

author
#0 lore raw

cover Bluetooth: Add MITM protection to SMP

This is a resend of the original patches (without modification) and two additional patches which adds the MITM protection into SMP.

This will not work for MITM protection without modifications to ther User side code (to take advantage of new MGMT Passkey interface) unless the other device is also a KeyboardDisplay device, or KeyboardOnly device.

If the remote side is a NoInputNoOutput device, it will work the same as it did prior to these patches.

Signature · 4 lines
Brian Gix
[email protected]
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum 
author
#1 lore raw

PATCH 1/5 Bluetooth: Add SMP support to user_confirm_reply

to enable User Confirmation during LE-SMP pairing.

---
 net/bluetooth/mgmt.c |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)
net/bluetooth/mgmt.c +19 -3
index 5562c21..129424e 100644
@@ -1445,6 +1445,7 @@ static int user_confirm_reply(struct sock *sk, u16 index, unsigned char *data,
 	u16 mgmt_op, hci_op;
 	struct pending_cmd *cmd;
 	struct hci_dev *hdev;
+	struct hci_conn *conn;
 	int err;
 
 	BT_DBG("");
@@ -1468,20 +1469,35 @@ static int user_confirm_reply(struct sock *sk, u16 index, unsigned char *data,
 
 	if (!test_bit(HCI_UP, &hdev->flags)) {
 		err = cmd_status(sk, index, mgmt_op, ENETDOWN);
-		goto failed;
+		goto done;
+	}
+
+	/* Route command to HCI (if ACL Link) or SMP (if LE Link) */
+	conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
+	if (!conn) {
+		conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->bdaddr);
+		if (!conn) {
+			err = cmd_status(sk, index, mgmt_op, ENOTCONN);
+			goto done;
+		}
+
+		/* Forward Confirm response to SMP */
+
+		err = cmd_status(sk, index, mgmt_op, 0);
+		goto done;
 	}
 
 	cmd = mgmt_pending_add(sk, mgmt_op, hdev, data, len);
 	if (!cmd) {
 		err = -ENOMEM;
-		goto failed;
+		goto done;
 	}
 
 	err = hci_send_cmd(hdev, hci_op, sizeof(cp->bdaddr), &cp->bdaddr);
 	if (err < 0)
 		mgmt_pending_remove(cmd);
 
-failed:
+done:
 	hci_dev_unlock_bh(hdev);
 	hci_dev_put(hdev);
 
Signature · 7 lines
1.7.7.2

-- 
Brian Gix
[email protected]
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum 
author
#3 lore raw

PATCH 2/5 Bluetooth: Add MGMT opcode for User Passkey entry

In reply to Brian Gix
---
 include/net/bluetooth/hci.h  |    8 +++
 include/net/bluetooth/mgmt.h |   11 +++
 net/bluetooth/mgmt.c         |  143 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 162 insertions(+), 0 deletions(-)
include/net/bluetooth/hci.h +8 -0
index 139ce2a..ac107b5 100644
@@ -453,6 +453,14 @@ struct hci_rp_user_confirm_reply {
 
 #define HCI_OP_USER_CONFIRM_NEG_REPLY	0x042d
 
+#define HCI_OP_USER_PASSKEY_REPLY		0x042e
+struct hci_cp_user_passkey_reply {
+	bdaddr_t bdaddr;
+	__u32	passkey;
+} __packed;
+
+#define HCI_OP_USER_PASSKEY_NEG_REPLY	0x042f
+
 #define HCI_OP_REMOTE_OOB_DATA_REPLY	0x0430
 struct hci_cp_remote_oob_data_reply {
 	bdaddr_t bdaddr;
include/net/bluetooth/mgmt.h +11 -0
index 8b07a83..190a9f5 100644
@@ -233,6 +233,17 @@ struct mgmt_cp_set_fast_connectable {
 	__u8 enable;
 } __packed;
 
+#define MGMT_OP_USER_PASSKEY_REPLY	0x0020
+struct mgmt_cp_user_passkey_reply {
+	bdaddr_t bdaddr;
+	__le32 passkey;
+} __packed;
+
+#define MGMT_OP_USER_PASSKEY_NEG_REPLY	0x0021
+struct mgmt_cp_user_passkey_neg_reply {
+	bdaddr_t bdaddr;
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16 opcode;
net/bluetooth/mgmt.c +143 -0

161 lines not on this page · raw message

Signature · 7 lines
1.7.7.2

-- 
Brian Gix
[email protected]
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum 
author
#5 lore raw

PATCH 3/5 Bluetooth: Add User Passkey entry to HCI Events

In reply to Brian Gix
---
 include/net/bluetooth/hci.h      |    5 +++
 include/net/bluetooth/hci_core.h |    4 ++
 net/bluetooth/hci_event.c        |   62 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 0 deletions(-)
include/net/bluetooth/hci.h +5 -0
index ac107b5..d1af139 100644
@@ -1084,6 +1084,11 @@ struct hci_ev_user_confirm_req {
 	__le32		passkey;
 } __packed;
 
+#define HCI_EV_USER_PASSKEY_REQUEST	0x34
+struct hci_ev_user_passkey_req {
+	bdaddr_t	bdaddr;
+} __packed;
+
 #define HCI_EV_REMOTE_OOB_DATA_REQUEST	0x35
 struct hci_ev_remote_oob_data_request {
 	bdaddr_t bdaddr;
include/net/bluetooth/hci_core.h +4 -0
index a67ff88..0b692ea 100644
@@ -933,6 +933,10 @@ int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
 								u8 status);
 int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev,
 						bdaddr_t *bdaddr, u8 status);
+int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
+								u8 status);
+int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev,
+						bdaddr_t *bdaddr, u8 status);
 int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status);
 int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
 int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
net/bluetooth/hci_event.c +62 -0

86 lines not on this page · raw message

Signature · 7 lines
1.7.7.2

-- 
Brian Gix
[email protected]
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum 
author
#8 lore raw

PATCH 4/5 Bluetooth: Cleanup blkcipher on SMP termination

In reply to Brian Gix
---
 net/bluetooth/smp.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
net/bluetooth/smp.c +7 -1
index 94e94ca..3b3726a 100644
@@ -379,7 +379,13 @@ static struct smp_chan *smp_chan_create(struct l2cap_conn *conn)
 
 void smp_chan_destroy(struct l2cap_conn *conn)
 {
-	kfree(conn->smp_chan);
+	struct smp_chan *smp = conn->smp_chan;
+
+	if (smp && !IS_ERR(smp->tfm))
+		crypto_free_blkcipher(smp->tfm);
+
+	kfree(smp);
+	conn->smp_chan = NULL;
 	hci_conn_put(conn->hcon);
 }
 
Signature · 7 lines
1.7.7.2

-- 
Brian Gix
[email protected]
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum 
author
#10 lore raw

PATCH 5/5 Bluetooth: Add support for MITM LE-SMP pairing

In reply to Brian Gix

Passkey entry and comparison only. Uses MGMT interface to request passkey and confirmation from user space.

---
 include/net/bluetooth/hci_core.h |    1 +
 include/net/bluetooth/smp.h      |    3 +
 net/bluetooth/mgmt.c             |   13 ++-
 net/bluetooth/smp.c              |  247 ++++++++++++++++++++++++++++++++++----
 4 files changed, 238 insertions(+), 26 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
index 0b692ea..be052d6 100644
@@ -312,6 +312,7 @@ struct hci_conn {
 	struct hci_dev	*hdev;
 	void		*l2cap_data;
 	void		*sco_data;
+	void		*smp_conn;
 
 	struct hci_conn	*link;
 
include/net/bluetooth/smp.h +3 -0
index 15b97d5..9ea77de 100644
@@ -124,6 +124,8 @@ struct smp_chan {
 	u8		pcnf[16]; /* SMP Pairing Confirm */
 	u8		tk[16]; /* SMP Temporary Key */
 	u8		smp_key_size;
+	u8		smp_tk_valid;
+	u8		smp_cfm_pending;
 	struct crypto_blkcipher	*tfm;
 	struct work_struct confirm;
 	struct work_struct random;
@@ -134,6 +136,7 @@ struct smp_chan {
 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);
+int smp_user_confirm_reply(struct hci_conn *conn, u16 mgmt_op, u32 passkey);
 
 void smp_chan_destroy(struct l2cap_conn *conn);
 
net/bluetooth/mgmt.c +10 -3
index f0f2ae2..8424ea2 100644
@@ -28,6 +28,7 @@
 #include <net/bluetooth/bluetooth.h>
 #include <net/bluetooth/hci_core.h>
 #include <net/bluetooth/mgmt.h>
+#include <net/bluetooth/smp.h>
 
 #define MGMT_VERSION	0
 #define MGMT_REVISION	1
@@ -1482,8 +1483,9 @@ static int user_confirm_reply(struct sock *sk, u16 index, unsigned char *data,
 		}
 
 		/* Forward Confirm response to SMP */
+		err = smp_user_confirm_reply(conn, mgmt_op, 0);
 
-		err = cmd_status(sk, index, mgmt_op, 0);
+		err = cmd_status(sk, index, mgmt_op, -err);
 		goto done;
 	}
 
@@ -1543,8 +1545,10 @@ static int user_passkey_reply(struct sock *sk, u16 index, unsigned char *data,
 		}
 
 		/* Forward Passkey response to SMP */
+		err = smp_user_confirm_reply(conn, MGMT_OP_USER_PASSKEY_REPLY,
+						le32_to_cpu(cp->passkey));
 
-		err = cmd_status(sk, index, MGMT_OP_USER_PASSKEY_REPLY, 0);
+		err = cmd_status(sk, index, MGMT_OP_USER_PASSKEY_REPLY, -err);
 		goto done;
 	}
 
@@ -1604,8 +1608,11 @@ static int user_passkey_neg_reply(struct sock *sk, u16 index,
 		}
 
 		/* Forward Passkey response to SMP */
+		err = smp_user_confirm_reply(conn,
+					MGMT_OP_USER_PASSKEY_NEG_REPLY, 0);
 
-		err = cmd_status(sk, index, MGMT_OP_USER_PASSKEY_NEG_REPLY, 0);
+		err = cmd_status(sk, index, MGMT_OP_USER_PASSKEY_NEG_REPLY,
+									-err);
 		goto done;
 	}
 
net/bluetooth/smp.c +224 -23

417 lines not on this page · raw message

Signature · 7 lines
1.7.7.2

-- 
Brian Gix
[email protected]
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum 
maintainer
#2 lore raw

Re: [PATCH 1/5] Bluetooth: Add SMP support to user_confirm_reply

In reply to Brian Gix

Hi Brian,

Quoted 20 lines

to enable User Confirmation during LE-SMP pairing.

---
 net/bluetooth/mgmt.c |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)
net/bluetooth/mgmt.c +1 -0
index 5562c21..129424e 100644
@@ -1445,6 +1445,7 @@ static int user_confirm_reply(struct sock *sk, u16 index, unsigned char *data,
 	u16 mgmt_op, hci_op;
 	struct pending_cmd *cmd;
 	struct hci_dev *hdev;
+	struct hci_conn *conn;
 	int err;
 
 	BT_DBG("");

net/bluetooth/mgmt.c static int user_confirm_reply(struct sock *sk, u16 index, unsigned char *data, · line 1475

Quoted 8 lines
net/bluetooth/mgmt.c +4 -1
@@ -1468,20 +1469,35 @@ static int user_confirm_reply(struct sock *sk, u16 index, unsigned char *data,
 
 	if (!test_bit(HCI_UP, &hdev->flags)) {
 		err = cmd_status(sk, index, mgmt_op, ENETDOWN);
-		goto failed;
+		goto done;
+	}
+
+	/* Route command to HCI (if ACL Link) or SMP (if LE Link) */

actually this is only have of what you are doing here. So something like this would be better (feel free to make it sounds nicer):

/*
* Check for an existing ACL link, if present use paring via
* HCI commands.
*
* If no ACL link is present, check for an LE link and if
* present, forward pairing handling to SMP engine. *
* If neither ACL nor LE links are present, fail with error. */

Quoted 4 lines
net/bluetooth/mgmt.c +4 -0
+	conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
+	if (!conn) {
+		conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->bdaddr);
+		if (!conn) {

net/bluetooth/mgmt.c static int user_confirm_reply(struct sock *sk, u16 index, unsigned char *data, · line 1489

Quoted 10 lines
net/bluetooth/mgmt.c +8 -0
+			err = cmd_status(sk, index, mgmt_op, ENOTCONN);
+			goto done;
+		}
+
+		/* Forward Confirm response to SMP */
+
+		err = cmd_status(sk, index, mgmt_op, 0);
+		goto done;
 	}
 
	/* Continue with pairing via HCI */

net/bluetooth/mgmt.c static int user_confirm_reply(struct sock *sk, u16 index, unsigned char *data, · line 1494

Quoted 6 lines
net/bluetooth/mgmt.c +1 -1
 	cmd = mgmt_pending_add(sk, mgmt_op, hdev, data, len);
 	if (!cmd) {
 		err = -ENOMEM;
-		goto failed;
+		goto done;
 	}

Since I stumbled over the logic already twice and had to twist my brain to ensure that it is correct, a comment is really needed.

Regards

Marcel

maintainer Acked-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] Bluetooth: Add MGMT opcode for User Passkey entry

In reply to Brian Gix

Hi Brian,

Quoted 38 lines
---
 include/net/bluetooth/hci.h  |    8 +++
 include/net/bluetooth/mgmt.h |   11 +++
 net/bluetooth/mgmt.c         |  143 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 162 insertions(+), 0 deletions(-)
include/net/bluetooth/hci.h +8 -0
index 139ce2a..ac107b5 100644
@@ -453,6 +453,14 @@ struct hci_rp_user_confirm_reply {
 
 #define HCI_OP_USER_CONFIRM_NEG_REPLY	0x042d
 
+#define HCI_OP_USER_PASSKEY_REPLY		0x042e
+struct hci_cp_user_passkey_reply {
+	bdaddr_t bdaddr;
+	__u32	passkey;
+} __packed;
+
+#define HCI_OP_USER_PASSKEY_NEG_REPLY	0x042f
+
 #define HCI_OP_REMOTE_OOB_DATA_REPLY	0x0430
 struct hci_cp_remote_oob_data_reply {
 	bdaddr_t bdaddr;
include/net/bluetooth/mgmt.h +4 -0
index 8b07a83..190a9f5 100644
@@ -233,6 +233,17 @@ struct mgmt_cp_set_fast_connectable {
 	__u8 enable;
 } __packed;
 
+#define MGMT_OP_USER_PASSKEY_REPLY	0x0020
+struct mgmt_cp_user_passkey_reply {
+	bdaddr_t bdaddr;
+	__le32 passkey;

include/net/bluetooth/mgmt.h struct mgmt_cp_set_fast_connectable { · line 249

Quoted 10 lines
include/net/bluetooth/mgmt.h +7 -0
+} __packed;
+
+#define MGMT_OP_USER_PASSKEY_NEG_REPLY	0x0021
+struct mgmt_cp_user_passkey_neg_reply {
+	bdaddr_t bdaddr;
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16 opcode;

please split this part into a separate and then it is fine with me. Feel free to add the ACK right away.

Quoted 120 lines
net/bluetooth/mgmt.c +112 -0
index 129424e..f0f2ae2 100644
@@ -1504,6 +1504,128 @@ done:
 	return err;
 }
 
+static int user_passkey_reply(struct sock *sk, u16 index, unsigned char *data,
+									u16 len)
+{
+	struct mgmt_cp_user_passkey_reply *cp = (void *) data;
+	struct pending_cmd *cmd;
+	struct hci_dev *hdev;
+	struct hci_conn *conn;
+	int err = 0;
+
+	BT_DBG("");
+
+	if (len != sizeof(*cp))
+		return cmd_status(sk, index, MGMT_OP_USER_PASSKEY_REPLY,
+									EINVAL);
+
+	hdev = hci_dev_get(index);
+	if (!hdev)
+		return cmd_status(sk, index, MGMT_OP_USER_PASSKEY_REPLY,
+									ENODEV);
+
+	hci_dev_lock_bh(hdev);
+
+	if (!test_bit(HCI_UP, &hdev->flags)) {
+		err = cmd_status(sk, index, MGMT_OP_USER_PASSKEY_REPLY,
+								ENETDOWN);
+		goto done;
+	}
+
+	/* Route command to HCI (if ACL Link) or SMP (if LE Link) */
+	conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
+	if (!conn) {
+		conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->bdaddr);
+		if (!conn) {
+			err = cmd_status(sk, index, MGMT_OP_USER_PASSKEY_REPLY,
+								ENOTCONN);
+			goto done;
+		}
+
+		/* Forward Passkey response to SMP */
+
+		err = cmd_status(sk, index, MGMT_OP_USER_PASSKEY_REPLY, 0);
+		goto done;
+	}
+
+	cmd = mgmt_pending_add(sk, MGMT_OP_USER_PASSKEY_REPLY, hdev, data, len);
+	if (!cmd) {
+		err = -ENOMEM;
+		goto done;
+	}
+
+	err = hci_send_cmd(hdev, HCI_OP_USER_PASSKEY_REPLY, len, cp);
+	if (err < 0)
+		mgmt_pending_remove(cmd);
+
+done:
+	hci_dev_unlock_bh(hdev);
+	hci_dev_put(hdev);
+
+	return err;
+}
+
+static int user_passkey_neg_reply(struct sock *sk, u16 index,
+						unsigned char *data, u16 len)
+{
+	struct mgmt_cp_user_passkey_neg_reply *cp = (void *) data;
+	struct pending_cmd *cmd;
+	struct hci_dev *hdev;
+	struct hci_conn *conn;
+	int err = 0;
+
+	BT_DBG("");
+
+	if (len != sizeof(*cp))
+		return cmd_status(sk, index, MGMT_OP_USER_PASSKEY_NEG_REPLY,
+									EINVAL);
+
+	hdev = hci_dev_get(index);
+	if (!hdev)
+		return cmd_status(sk, index, MGMT_OP_USER_PASSKEY_NEG_REPLY,
+									ENODEV);
+
+	hci_dev_lock_bh(hdev);
+
+	if (!test_bit(HCI_UP, &hdev->flags)) {
+		err = cmd_status(sk, index, MGMT_OP_USER_PASSKEY_NEG_REPLY,
+								ENETDOWN);
+		goto done;
+	}
+
+	conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
+	if (!conn) {
+		conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->bdaddr);
+		if (!conn) {
+			err = cmd_status(sk, index,
+					MGMT_OP_USER_PASSKEY_NEG_REPLY,
+					ENOTCONN);
+			goto done;
+		}
+
+		/* Forward Passkey response to SMP */
+
+		err = cmd_status(sk, index, MGMT_OP_USER_PASSKEY_NEG_REPLY, 0);
+		goto done;
+	}
+
+	cmd = mgmt_pending_add(sk, MGMT_OP_USER_PASSKEY_NEG_REPLY, hdev, data,
+									len);
+	if (!cmd) {
+		err = -ENOMEM;
+		goto done;
+	}
+

net/bluetooth/mgmt.c done: · line 1628

Quoted 10 lines
net/bluetooth/mgmt.c +10 -0
+	err = hci_send_cmd(hdev, HCI_OP_USER_PASSKEY_NEG_REPLY, len, cp);
+	if (err < 0)
+		mgmt_pending_remove(cmd);
+
+done:
+	hci_dev_unlock_bh(hdev);
+	hci_dev_put(hdev);
+
+	return err;
+}

Actually passkey, passkey-neg, confirm, neg-confirm contain a lot of the same code just with a different parameter. I can be all generalized into a helper function. Only the initial parsing of the HCI command needs to be different. So please clean this up.

Once we a nice common helper, the extra comments and also looking becomes central in one single place. Way nicer.

Regards

Marcel

maintainer
#6 lore raw

Re: [PATCH 3/5] Bluetooth: Add User Passkey entry to HCI Events

In reply to Brian Gix

Hi Brian,

Quoted 13 lines
---
 include/net/bluetooth/hci.h      |    5 +++
 include/net/bluetooth/hci_core.h |    4 ++
 net/bluetooth/hci_event.c        |   62 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 0 deletions(-)
include/net/bluetooth/hci.h +0 -0
index ac107b5..d1af139 100644
@@ -1084,6 +1084,11 @@ struct hci_ev_user_confirm_req {
 	__le32		passkey;

include/net/bluetooth/hci.h struct hci_ev_user_confirm_req { · line 1094

Quoted 10 lines
include/net/bluetooth/hci.h +5 -0
 } __packed;
 
+#define HCI_EV_USER_PASSKEY_REQUEST	0x34
+struct hci_ev_user_passkey_req {
+	bdaddr_t	bdaddr;
+} __packed;
+
 #define HCI_EV_REMOTE_OOB_DATA_REQUEST	0x35
 struct hci_ev_remote_oob_data_request {
 	bdaddr_t bdaddr;

this should go into a separate patch. And please get into the habit of actually writing a commit message. Not just a commit subject.

Quoted 81 lines
include/net/bluetooth/hci_core.h +4 -0
index a67ff88..0b692ea 100644
@@ -933,6 +933,10 @@ int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
 								u8 status);
 int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev,
 						bdaddr_t *bdaddr, u8 status);
+int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
+								u8 status);
+int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev,
+						bdaddr_t *bdaddr, u8 status);
 int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status);
 int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
 int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
net/bluetooth/hci_event.c +44 -0
index 0d55d00..a425926 100644
@@ -927,6 +927,37 @@ static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev,
 	hci_dev_unlock(hdev);
 }
 
+static void hci_cc_user_passkey_reply(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
+
+	BT_DBG("%s status 0x%x", hdev->name, rp->status);
+
+	hci_dev_lock(hdev);
+
+	if (test_bit(HCI_MGMT, &hdev->flags))
+		mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr,
+								rp->status);
+
+	hci_dev_unlock(hdev);
+}
+
+static void hci_cc_user_passkey_neg_reply(struct hci_dev *hdev,
+							struct sk_buff *skb)
+{
+	struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
+
+	BT_DBG("%s status 0x%x", hdev->name, rp->status);
+
+	hci_dev_lock(hdev);
+
+	if (test_bit(HCI_MGMT, &hdev->flags))
+		mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr,
+								rp->status);
+
+	hci_dev_unlock(hdev);
+}
+
 static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev,
 							struct sk_buff *skb)
 {
@@ -2011,6 +2042,14 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk
 		hci_cc_user_confirm_neg_reply(hdev, skb);
 		break;
 
+	case HCI_OP_USER_PASSKEY_REPLY:
+		hci_cc_user_passkey_reply(hdev, skb);
+		break;
+
+	case HCI_OP_USER_PASSKEY_NEG_REPLY:
+		hci_cc_user_passkey_neg_reply(hdev, skb);
+		break;
+
 	case HCI_OP_LE_SET_SCAN_ENABLE:
 		hci_cc_le_set_scan_enable(hdev, skb);
 		break;
@@ -2770,6 +2809,25 @@ unlock:
 	hci_dev_unlock(hdev);
 }
 
+static inline void hci_user_passkey_request_evt(struct hci_dev *hdev,
+							struct sk_buff *skb)
+{
+	struct hci_ev_user_passkey_req *ev = (void *) skb->data;
+

net/bluetooth/hci_event.c unlock: · line 2826

Quoted 10 lines
net/bluetooth/hci_event.c +10 -0
+	BT_DBG("%s", hdev->name);
+
+	hci_dev_lock(hdev);
+
+	/* Passkey Request is a degenerate case of User Confirm */
+	if (test_bit(HCI_MGMT, &hdev->flags))
+		mgmt_user_confirm_request(hdev, &ev->bdaddr, 0, 0);
+	else
+		hci_send_cmd(hdev, HCI_OP_USER_PASSKEY_NEG_REPLY,
+					sizeof(ev->bdaddr), &ev->bdaddr);

We might want a comment here that this needs fixing ;)

Quoted 21 lines
net/bluetooth/hci_event.c +8 -0
+
+	hci_dev_unlock(hdev);
+}
+
 static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct hci_ev_simple_pair_complete *ev = (void *) skb->data;
@@ -3109,6 +3167,10 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
 		hci_user_confirm_request_evt(hdev, skb);
 		break;
 
+	case HCI_EV_USER_PASSKEY_REQUEST:
+		hci_user_passkey_request_evt(hdev, skb);
+		break;
+
 	case HCI_EV_SIMPLE_PAIR_COMPLETE:
 		hci_simple_pair_complete_evt(hdev, skb);
 		break;
Signature · 1 line
1.7.7.2

Regards

Marcel

maintainer Acked-by on v1 4/5
#9 lore raw

Re: [PATCH 4/5] Bluetooth: Cleanup blkcipher on SMP termination

In reply to Brian Gix

Hi Brian,

Quoted 4 lines
---
 net/bluetooth/smp.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

But please get into the habit of having proper commit messages with explanation.

I wanna be able to read the commit message and then compare that the code does exactly what you claim it to be doing.

Regards

Marcel

#7 lore raw

Re: [PATCH 3/5] Bluetooth: Add User Passkey entry to HCI Events

In reply to Marcel Holtmann

Hi,

Quoted 9 lines · Marcel Holtmann
Quoted 9 lines
net/bluetooth/hci_event.c +9 -0
+static inline void hci_user_passkey_request_evt(struct hci_dev *hdev,
+							struct sk_buff *skb)
+{
+	struct hci_ev_user_passkey_req *ev = (void *) skb->data;
+
+	BT_DBG("%s", hdev->name);
+
+	hci_dev_lock(hdev);
+
Quoted 8 lines

net/bluetooth/hci_event.c unlock: · line 2826

Quoted 6 lines
net/bluetooth/hci_event.c +6 -0
+	/* Passkey Request is a degenerate case of User Confirm */
+	if (test_bit(HCI_MGMT, &hdev->flags))
+		mgmt_user_confirm_request(hdev, &ev->bdaddr, 0, 0);
+	else
+		hci_send_cmd(hdev, HCI_OP_USER_PASSKEY_NEG_REPLY,
+					sizeof(ev->bdaddr), &ev->bdaddr);

We might want a comment here that this needs fixing ;)

If HCI_MGMT isn't set this code should do nothing. In such a case it's likely that hciops is running in user-space and will take care of this request.

Johan

maintainer
#11 lore raw

Re: [PATCH 5/5] Bluetooth: Add support for MITM LE-SMP pairing

In reply to Brian Gix

Hi Brian,

Quoted 2 lines

Passkey entry and comparison only. Uses MGMT interface to request passkey and confirmation from user space.

can you please split this patch into smaller chunks. It looks like some of them are just small bug fixes for error handling.

And I see a lot of code duplication here as well. I prefer we introduce proper helpers for certain common patterns.

Regards

Marcel