Commit 1c1def09 authored by Vinicius Costa Gomes's avatar Vinicius Costa Gomes Committed by Gustavo F. Padovan

Bluetooth: Move SMP fields to a separate structure

The objective is to make the core to have as little as possible
information about SMP procedures and logic. Now, all the SMP
specific information is hidden from the core.
Signed-off-by: default avatarVinicius Costa Gomes <vinicius.gomes@openbossa.org>
Signed-off-by: default avatarGustavo F. Padovan <padovan@profusion.mobi>
parent 142c69c6
...@@ -195,8 +195,6 @@ struct hci_dev { ...@@ -195,8 +195,6 @@ struct hci_dev {
__u16 init_last_cmd; __u16 init_last_cmd;
struct crypto_blkcipher *tfm;
struct inquiry_cache inq_cache; struct inquiry_cache inq_cache;
struct hci_conn_hash conn_hash; struct hci_conn_hash conn_hash;
struct list_head blacklist; struct list_head blacklist;
......
...@@ -409,14 +409,8 @@ struct l2cap_conn { ...@@ -409,14 +409,8 @@ struct l2cap_conn {
__u8 disc_reason; __u8 disc_reason;
__u8 preq[7]; /* SMP Pairing Request */
__u8 prsp[7]; /* SMP Pairing Response */
__u8 prnd[16]; /* SMP Pairing Random */
__u8 pcnf[16]; /* SMP Pairing Confirm */
__u8 tk[16]; /* SMP Temporary Key */
__u8 smp_key_size;
struct timer_list security_timer; struct timer_list security_timer;
struct smp_chan *smp_chan;
struct list_head chan_l; struct list_head chan_l;
rwlock_t chan_lock; rwlock_t chan_lock;
......
...@@ -115,6 +115,16 @@ struct smp_cmd_security_req { ...@@ -115,6 +115,16 @@ struct smp_cmd_security_req {
#define SMP_MIN_ENC_KEY_SIZE 7 #define SMP_MIN_ENC_KEY_SIZE 7
#define SMP_MAX_ENC_KEY_SIZE 16 #define SMP_MAX_ENC_KEY_SIZE 16
struct smp_chan {
u8 preq[7]; /* SMP Pairing Request */
u8 prsp[7]; /* SMP Pairing Response */
u8 prnd[16]; /* SMP Pairing Random */
u8 pcnf[16]; /* SMP Pairing Confirm */
u8 tk[16]; /* SMP Temporary Key */
u8 smp_key_size;
struct crypto_blkcipher *tfm;
};
/* SMP Commands */ /* SMP Commands */
int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level); 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_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb);
......
...@@ -1523,11 +1523,6 @@ int hci_register_dev(struct hci_dev *hdev) ...@@ -1523,11 +1523,6 @@ int hci_register_dev(struct hci_dev *hdev)
if (!hdev->workqueue) if (!hdev->workqueue)
goto nomem; goto nomem;
hdev->tfm = crypto_alloc_blkcipher("ecb(aes)", 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(hdev->tfm))
BT_INFO("Failed to load transform for ecb(aes): %ld",
PTR_ERR(hdev->tfm));
hci_register_sysfs(hdev); hci_register_sysfs(hdev);
hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev, hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev,
...@@ -1576,9 +1571,6 @@ int hci_unregister_dev(struct hci_dev *hdev) ...@@ -1576,9 +1571,6 @@ int hci_unregister_dev(struct hci_dev *hdev)
!test_bit(HCI_SETUP, &hdev->flags)) !test_bit(HCI_SETUP, &hdev->flags))
mgmt_index_removed(hdev->id); mgmt_index_removed(hdev->id);
if (!IS_ERR(hdev->tfm))
crypto_free_blkcipher(hdev->tfm);
hci_notify(hdev, HCI_DEV_UNREG); hci_notify(hdev, HCI_DEV_UNREG);
if (hdev->rfkill) { if (hdev->rfkill) {
......
...@@ -232,11 +232,13 @@ static void build_pairing_cmd(struct l2cap_conn *conn, ...@@ -232,11 +232,13 @@ static void build_pairing_cmd(struct l2cap_conn *conn,
static u8 check_enc_key_size(struct l2cap_conn *conn, __u8 max_key_size) static u8 check_enc_key_size(struct l2cap_conn *conn, __u8 max_key_size)
{ {
struct smp_chan *smp = conn->smp_chan;
if ((max_key_size > SMP_MAX_ENC_KEY_SIZE) || if ((max_key_size > SMP_MAX_ENC_KEY_SIZE) ||
(max_key_size < SMP_MIN_ENC_KEY_SIZE)) (max_key_size < SMP_MIN_ENC_KEY_SIZE))
return SMP_ENC_KEY_SIZE; return SMP_ENC_KEY_SIZE;
conn->smp_key_size = max_key_size; smp->smp_key_size = max_key_size;
return 0; return 0;
} }
...@@ -244,6 +246,7 @@ static u8 check_enc_key_size(struct l2cap_conn *conn, __u8 max_key_size) ...@@ -244,6 +246,7 @@ static u8 check_enc_key_size(struct l2cap_conn *conn, __u8 max_key_size)
static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb) static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)
{ {
struct smp_cmd_pairing rsp, *req = (void *) skb->data; struct smp_cmd_pairing rsp, *req = (void *) skb->data;
struct smp_chan *smp = conn->smp_chan;
u8 key_size; u8 key_size;
BT_DBG("conn %p", conn); BT_DBG("conn %p", conn);
...@@ -251,8 +254,8 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -251,8 +254,8 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)
if (!test_and_set_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->pend)) if (!test_and_set_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->pend))
hci_conn_hold(conn->hcon); hci_conn_hold(conn->hcon);
conn->preq[0] = SMP_CMD_PAIRING_REQ; smp->preq[0] = SMP_CMD_PAIRING_REQ;
memcpy(&conn->preq[1], req, sizeof(*req)); memcpy(&smp->preq[1], req, sizeof(*req));
skb_pull(skb, sizeof(*req)); skb_pull(skb, sizeof(*req));
if (req->oob_flag) if (req->oob_flag)
...@@ -266,10 +269,10 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -266,10 +269,10 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)
return SMP_ENC_KEY_SIZE; return SMP_ENC_KEY_SIZE;
/* Just works */ /* Just works */
memset(conn->tk, 0, sizeof(conn->tk)); memset(smp->tk, 0, sizeof(smp->tk));
conn->prsp[0] = SMP_CMD_PAIRING_RSP; smp->prsp[0] = SMP_CMD_PAIRING_RSP;
memcpy(&conn->prsp[1], &rsp, sizeof(rsp)); memcpy(&smp->prsp[1], &rsp, sizeof(rsp));
smp_send_cmd(conn, SMP_CMD_PAIRING_RSP, sizeof(rsp), &rsp); smp_send_cmd(conn, SMP_CMD_PAIRING_RSP, sizeof(rsp), &rsp);
...@@ -280,7 +283,9 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -280,7 +283,9 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)
{ {
struct smp_cmd_pairing *req, *rsp = (void *) skb->data; struct smp_cmd_pairing *req, *rsp = (void *) skb->data;
struct smp_cmd_pairing_confirm cp; struct smp_cmd_pairing_confirm cp;
struct crypto_blkcipher *tfm = conn->hcon->hdev->tfm; struct smp_chan *smp = conn->smp_chan;
struct crypto_blkcipher *tfm = smp->tfm;
int ret; int ret;
u8 res[16], key_size; u8 res[16], key_size;
...@@ -288,7 +293,7 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -288,7 +293,7 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)
skb_pull(skb, sizeof(*rsp)); skb_pull(skb, sizeof(*rsp));
req = (void *) &conn->preq[1]; req = (void *) &smp->preq[1];
key_size = min(req->max_key_size, rsp->max_key_size); key_size = min(req->max_key_size, rsp->max_key_size);
if (check_enc_key_size(conn, key_size)) if (check_enc_key_size(conn, key_size))
...@@ -298,16 +303,16 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -298,16 +303,16 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)
return SMP_OOB_NOT_AVAIL; return SMP_OOB_NOT_AVAIL;
/* Just works */ /* Just works */
memset(conn->tk, 0, sizeof(conn->tk)); memset(smp->tk, 0, sizeof(smp->tk));
conn->prsp[0] = SMP_CMD_PAIRING_RSP; smp->prsp[0] = SMP_CMD_PAIRING_RSP;
memcpy(&conn->prsp[1], rsp, sizeof(*rsp)); memcpy(&smp->prsp[1], rsp, sizeof(*rsp));
ret = smp_rand(conn->prnd); ret = smp_rand(smp->prnd);
if (ret) if (ret)
return SMP_UNSPECIFIED; return SMP_UNSPECIFIED;
ret = smp_c1(tfm, conn->tk, conn->prnd, conn->preq, conn->prsp, 0, ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp, 0,
conn->src, conn->hcon->dst_type, conn->dst, res); conn->src, conn->hcon->dst_type, conn->dst, res);
if (ret) if (ret)
return SMP_UNSPECIFIED; return SMP_UNSPECIFIED;
...@@ -321,17 +326,18 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -321,17 +326,18 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)
static u8 smp_cmd_pairing_confirm(struct l2cap_conn *conn, struct sk_buff *skb) static u8 smp_cmd_pairing_confirm(struct l2cap_conn *conn, struct sk_buff *skb)
{ {
struct crypto_blkcipher *tfm = conn->hcon->hdev->tfm; struct smp_chan *smp = conn->smp_chan;
struct crypto_blkcipher *tfm = smp->tfm;
BT_DBG("conn %p %s", conn, conn->hcon->out ? "master" : "slave"); BT_DBG("conn %p %s", conn, conn->hcon->out ? "master" : "slave");
memcpy(conn->pcnf, skb->data, sizeof(conn->pcnf)); memcpy(smp->pcnf, skb->data, sizeof(smp->pcnf));
skb_pull(skb, sizeof(conn->pcnf)); skb_pull(skb, sizeof(smp->pcnf));
if (conn->hcon->out) { if (conn->hcon->out) {
u8 random[16]; u8 random[16];
swap128(conn->prnd, random); swap128(smp->prnd, random);
smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(random), smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(random),
random); random);
} else { } else {
...@@ -339,11 +345,11 @@ static u8 smp_cmd_pairing_confirm(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -339,11 +345,11 @@ static u8 smp_cmd_pairing_confirm(struct l2cap_conn *conn, struct sk_buff *skb)
int ret; int ret;
u8 res[16]; u8 res[16];
ret = smp_rand(conn->prnd); ret = smp_rand(smp->prnd);
if (ret) if (ret)
return SMP_UNSPECIFIED; return SMP_UNSPECIFIED;
ret = smp_c1(tfm, conn->tk, conn->prnd, conn->preq, conn->prsp, ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp,
conn->hcon->dst_type, conn->dst, conn->hcon->dst_type, conn->dst,
0, conn->src, res); 0, conn->src, res);
if (ret) if (ret)
...@@ -360,7 +366,8 @@ static u8 smp_cmd_pairing_confirm(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -360,7 +366,8 @@ static u8 smp_cmd_pairing_confirm(struct l2cap_conn *conn, struct sk_buff *skb)
static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
{ {
struct hci_conn *hcon = conn->hcon; struct hci_conn *hcon = conn->hcon;
struct crypto_blkcipher *tfm = hcon->hdev->tfm; struct smp_chan *smp = conn->smp_chan;
struct crypto_blkcipher *tfm = smp->tfm;
int ret; int ret;
u8 key[16], res[16], random[16], confirm[16]; u8 key[16], res[16], random[16], confirm[16];
...@@ -368,11 +375,11 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -368,11 +375,11 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
skb_pull(skb, sizeof(random)); skb_pull(skb, sizeof(random));
if (conn->hcon->out) if (conn->hcon->out)
ret = smp_c1(tfm, conn->tk, random, conn->preq, conn->prsp, 0, ret = smp_c1(tfm, smp->tk, random, smp->preq, smp->prsp, 0,
conn->src, conn->hcon->dst_type, conn->dst, conn->src, conn->hcon->dst_type, conn->dst,
res); res);
else else
ret = smp_c1(tfm, conn->tk, random, conn->preq, conn->prsp, ret = smp_c1(tfm, smp->tk, random, smp->preq, smp->prsp,
conn->hcon->dst_type, conn->dst, 0, conn->src, conn->hcon->dst_type, conn->dst, 0, conn->src,
res); res);
if (ret) if (ret)
...@@ -382,7 +389,7 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -382,7 +389,7 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
swap128(res, confirm); swap128(res, confirm);
if (memcmp(conn->pcnf, confirm, sizeof(conn->pcnf)) != 0) { if (memcmp(smp->pcnf, confirm, sizeof(smp->pcnf)) != 0) {
BT_ERR("Pairing failed (confirmation values mismatch)"); BT_ERR("Pairing failed (confirmation values mismatch)");
return SMP_CONFIRM_FAILED; return SMP_CONFIRM_FAILED;
} }
...@@ -394,17 +401,17 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -394,17 +401,17 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
memset(rand, 0, sizeof(rand)); memset(rand, 0, sizeof(rand));
ediv = 0; ediv = 0;
smp_s1(tfm, conn->tk, random, conn->prnd, key); smp_s1(tfm, smp->tk, random, smp->prnd, key);
swap128(key, stk); swap128(key, stk);
memset(stk + conn->smp_key_size, 0, memset(stk + smp->smp_key_size, 0,
SMP_MAX_ENC_KEY_SIZE - conn->smp_key_size); SMP_MAX_ENC_KEY_SIZE - smp->smp_key_size);
if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->pend)) if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->pend))
return SMP_UNSPECIFIED; return SMP_UNSPECIFIED;
hci_le_start_enc(hcon, ediv, rand, stk); hci_le_start_enc(hcon, ediv, rand, stk);
hcon->enc_key_size = conn->smp_key_size; hcon->enc_key_size = smp->smp_key_size;
} else { } else {
u8 stk[16], r[16], rand[8]; u8 stk[16], r[16], rand[8];
__le16 ediv; __le16 ediv;
...@@ -412,16 +419,16 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -412,16 +419,16 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
memset(rand, 0, sizeof(rand)); memset(rand, 0, sizeof(rand));
ediv = 0; ediv = 0;
swap128(conn->prnd, r); swap128(smp->prnd, r);
smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(r), r); smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(r), r);
smp_s1(tfm, conn->tk, conn->prnd, random, key); smp_s1(tfm, smp->tk, smp->prnd, random, key);
swap128(key, stk); swap128(key, stk);
memset(stk + conn->smp_key_size, 0, memset(stk + smp->smp_key_size, 0,
SMP_MAX_ENC_KEY_SIZE - conn->smp_key_size); SMP_MAX_ENC_KEY_SIZE - smp->smp_key_size);
hci_add_ltk(conn->hcon->hdev, 0, conn->dst, conn->smp_key_size, hci_add_ltk(conn->hcon->hdev, 0, conn->dst, smp->smp_key_size,
ediv, rand, stk); ediv, rand, stk);
} }
...@@ -433,6 +440,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -433,6 +440,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)
struct smp_cmd_security_req *rp = (void *) skb->data; struct smp_cmd_security_req *rp = (void *) skb->data;
struct smp_cmd_pairing cp; struct smp_cmd_pairing cp;
struct hci_conn *hcon = conn->hcon; struct hci_conn *hcon = conn->hcon;
struct smp_chan *smp = conn->smp_chan;
BT_DBG("conn %p", conn); BT_DBG("conn %p", conn);
...@@ -446,8 +454,8 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -446,8 +454,8 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)
memset(&cp, 0, sizeof(cp)); memset(&cp, 0, sizeof(cp));
build_pairing_cmd(conn, &cp, NULL, rp->auth_req); build_pairing_cmd(conn, &cp, NULL, rp->auth_req);
conn->preq[0] = SMP_CMD_PAIRING_REQ; smp->preq[0] = SMP_CMD_PAIRING_REQ;
memcpy(&conn->preq[1], &cp, sizeof(cp)); memcpy(&smp->preq[1], &cp, sizeof(cp));
smp_send_cmd(conn, SMP_CMD_PAIRING_REQ, sizeof(cp), &cp); smp_send_cmd(conn, SMP_CMD_PAIRING_REQ, sizeof(cp), &cp);
...@@ -457,6 +465,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -457,6 +465,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)
int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level) int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level)
{ {
struct hci_conn *hcon = conn->hcon; struct hci_conn *hcon = conn->hcon;
struct smp_chan *smp = conn->smp_chan;
__u8 authreq; __u8 authreq;
BT_DBG("conn %p hcon %p level 0x%2.2x", conn, hcon, sec_level); BT_DBG("conn %p hcon %p level 0x%2.2x", conn, hcon, sec_level);
...@@ -464,9 +473,6 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level) ...@@ -464,9 +473,6 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level)
if (!lmp_host_le_capable(hcon->hdev)) if (!lmp_host_le_capable(hcon->hdev))
return 1; return 1;
if (IS_ERR(hcon->hdev->tfm))
return 1;
if (sec_level == BT_SECURITY_LOW) if (sec_level == BT_SECURITY_LOW)
return 1; return 1;
...@@ -505,8 +511,8 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level) ...@@ -505,8 +511,8 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level)
struct smp_cmd_pairing cp; struct smp_cmd_pairing cp;
build_pairing_cmd(conn, &cp, NULL, authreq); build_pairing_cmd(conn, &cp, NULL, authreq);
conn->preq[0] = SMP_CMD_PAIRING_REQ; smp->preq[0] = SMP_CMD_PAIRING_REQ;
memcpy(&conn->preq[1], &cp, sizeof(cp)); memcpy(&smp->preq[1], &cp, sizeof(cp));
smp_send_cmd(conn, SMP_CMD_PAIRING_REQ, sizeof(cp), &cp); smp_send_cmd(conn, SMP_CMD_PAIRING_REQ, sizeof(cp), &cp);
} else { } else {
...@@ -524,10 +530,11 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level) ...@@ -524,10 +530,11 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level)
static int smp_cmd_encrypt_info(struct l2cap_conn *conn, struct sk_buff *skb) static int smp_cmd_encrypt_info(struct l2cap_conn *conn, struct sk_buff *skb)
{ {
struct smp_cmd_encrypt_info *rp = (void *) skb->data; struct smp_cmd_encrypt_info *rp = (void *) skb->data;
struct smp_chan *smp = conn->smp_chan;
skb_pull(skb, sizeof(*rp)); skb_pull(skb, sizeof(*rp));
memcpy(conn->tk, rp->ltk, sizeof(conn->tk)); memcpy(smp->tk, rp->ltk, sizeof(smp->tk));
return 0; return 0;
} }
...@@ -535,11 +542,12 @@ static int smp_cmd_encrypt_info(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -535,11 +542,12 @@ static int smp_cmd_encrypt_info(struct l2cap_conn *conn, struct sk_buff *skb)
static int smp_cmd_master_ident(struct l2cap_conn *conn, struct sk_buff *skb) static int smp_cmd_master_ident(struct l2cap_conn *conn, struct sk_buff *skb)
{ {
struct smp_cmd_master_ident *rp = (void *) skb->data; struct smp_cmd_master_ident *rp = (void *) skb->data;
struct smp_chan *smp = conn->smp_chan;
skb_pull(skb, sizeof(*rp)); skb_pull(skb, sizeof(*rp));
hci_add_ltk(conn->hcon->hdev, 1, conn->src, conn->smp_key_size, hci_add_ltk(conn->hcon->hdev, 1, conn->src, smp->smp_key_size,
rp->ediv, rp->rand, conn->tk); rp->ediv, rp->rand, smp->tk);
smp_distribute_keys(conn, 1); smp_distribute_keys(conn, 1);
...@@ -558,12 +566,6 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -558,12 +566,6 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
goto done; goto done;
} }
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)); skb_pull(skb, sizeof(code));
switch (code) { switch (code) {
...@@ -627,23 +629,21 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -627,23 +629,21 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
int smp_distribute_keys(struct l2cap_conn *conn, __u8 force) int smp_distribute_keys(struct l2cap_conn *conn, __u8 force)
{ {
struct smp_cmd_pairing *req, *rsp; struct smp_cmd_pairing *req, *rsp;
struct smp_chan *smp = conn->smp_chan;
__u8 *keydist; __u8 *keydist;
BT_DBG("conn %p force %d", conn, force); BT_DBG("conn %p force %d", conn, force);
if (IS_ERR(conn->hcon->hdev->tfm))
return PTR_ERR(conn->hcon->hdev->tfm);
if (!test_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->pend)) if (!test_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->pend))
return 0; return 0;
rsp = (void *) &conn->prsp[1]; rsp = (void *) &smp->prsp[1];
/* The responder sends its keys first */ /* The responder sends its keys first */
if (!force && conn->hcon->out && (rsp->resp_key_dist & 0x07)) if (!force && conn->hcon->out && (rsp->resp_key_dist & 0x07))
return 0; return 0;
req = (void *) &conn->preq[1]; req = (void *) &smp->preq[1];
if (conn->hcon->out) { if (conn->hcon->out) {
keydist = &rsp->init_key_dist; keydist = &rsp->init_key_dist;
...@@ -667,7 +667,7 @@ int smp_distribute_keys(struct l2cap_conn *conn, __u8 force) ...@@ -667,7 +667,7 @@ int smp_distribute_keys(struct l2cap_conn *conn, __u8 force)
smp_send_cmd(conn, SMP_CMD_ENCRYPT_INFO, sizeof(enc), &enc); smp_send_cmd(conn, SMP_CMD_ENCRYPT_INFO, sizeof(enc), &enc);
hci_add_ltk(conn->hcon->hdev, 1, conn->dst, conn->smp_key_size, hci_add_ltk(conn->hcon->hdev, 1, conn->dst, smp->smp_key_size,
ediv, ident.rand, enc.ltk); ediv, ident.rand, enc.ltk);
ident.ediv = cpu_to_le16(ediv); ident.ediv = cpu_to_le16(ediv);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment