From 6de50c5aa6ddc00cb911ad8149f6db1dfb7e94a2 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 9 Feb 2016 17:23:53 +0100 Subject: [PATCH] Bluetooth: Store LE SC Public Key in SMP code There is no need to keep this in bt_dev structure as this is not used outside of SMP code. Change-Id: I24a1d9daffb4d382bf1ed07a5645e4cbdafa3c5e Signed-off-by: Szymon Janc --- net/bluetooth/hci_core.c | 3 +-- net/bluetooth/hci_core.h | 6 ------ net/bluetooth/smp.c | 17 ++++++++++------- net/bluetooth/smp.h | 2 +- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index bdf34cd75c2..c7d6e6ee9fb 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1069,8 +1069,7 @@ static void le_pkey_complete(struct net_buf *buf) return; } - memcpy(bt_dev.pkey, evt->key, sizeof(bt_dev.pkey)); - bt_smp_pkey_ready(); + bt_smp_pkey_ready(evt->key); } static void le_dhkey_complete(struct net_buf *buf) diff --git a/net/bluetooth/hci_core.h b/net/bluetooth/hci_core.h index 7b457872bc5..92af2925289 100644 --- a/net/bluetooth/hci_core.h +++ b/net/bluetooth/hci_core.h @@ -102,12 +102,6 @@ struct bt_dev { /* Registered HCI driver */ struct bt_driver *drv; - -/* TODO check tinycrypt define when ECC is added */ -#if defined(CONFIG_BLUETOOTH_SMP) && !defined(CONFIG_TINYCRYPT_ECC) - /* Public Key */ - uint8_t pkey[64]; -#endif }; extern struct bt_dev bt_dev; diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index 7a602d9e6d0..278e1622267 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c @@ -177,6 +177,8 @@ static struct bt_smp bt_smp_pool[CONFIG_BLUETOOTH_MAX_CONN]; static bool sc_supported; static bool sc_local_pkey_valid; +static uint8_t sc_pkey[64]; + static uint8_t get_io_capa(void) { if (!bt_auth) { @@ -931,7 +933,7 @@ static uint8_t smp_send_pairing_confirm(struct bt_smp *smp) req = net_buf_add(buf, sizeof(*req)); - if (smp_f4(bt_dev.pkey, smp->pkey, smp->prnd, r, req->val)) { + if (smp_f4(sc_pkey, smp->pkey, smp->prnd, r, req->val)) { net_buf_unref(buf); return BT_SMP_ERR_UNSPECIFIED; } @@ -1585,8 +1587,8 @@ static uint8_t sc_send_public_key(struct bt_smp *smp) req = net_buf_add(req_buf, sizeof(*req)); - memcpy(req->x, bt_dev.pkey, sizeof(req->x)); - memcpy(req->y, &bt_dev.pkey[32], sizeof(req->y)); + memcpy(req->x, sc_pkey, sizeof(req->x)); + memcpy(req->y, &sc_pkey[32], sizeof(req->y)); smp_send(smp, req_buf); @@ -1948,7 +1950,7 @@ static uint8_t sc_smp_check_confirm(struct bt_smp *smp) return BT_SMP_ERR_UNSPECIFIED; } - if (smp_f4(smp->pkey, bt_dev.pkey, smp->rrnd, r, cfm)) { + if (smp_f4(smp->pkey, sc_pkey, smp->rrnd, r, cfm)) { return BT_SMP_ERR_UNSPECIFIED; } @@ -1987,7 +1989,7 @@ static uint8_t smp_pairing_random(struct bt_smp *smp, struct net_buf *buf) switch (smp->method) { case PASSKEY_CONFIRM: /* compare passkey before calculating LTK */ - if (smp_g2(bt_dev.pkey, smp->pkey, smp->prnd, smp->rrnd, + if (smp_g2(sc_pkey, smp->pkey, smp->prnd, smp->rrnd, &passkey)) { return BT_SMP_ERR_UNSPECIFIED; } @@ -2029,7 +2031,7 @@ static uint8_t smp_pairing_random(struct bt_smp *smp, struct net_buf *buf) #if defined(CONFIG_BLUETOOTH_PERIPHERAL) switch (smp->method) { case PASSKEY_CONFIRM: - if (smp_g2(smp->pkey, bt_dev.pkey, smp->rrnd, smp->prnd, + if (smp_g2(smp->pkey, sc_pkey, smp->rrnd, smp->prnd, &passkey)) { return BT_SMP_ERR_UNSPECIFIED; } @@ -2576,12 +2578,13 @@ static void bt_smp_recv(struct bt_l2cap_chan *chan, struct net_buf *buf) } } -void bt_smp_pkey_ready(void) +void bt_smp_pkey_ready(const uint8_t *pkey) { int i; BT_DBG(""); + memcpy(sc_pkey, pkey, 64); sc_local_pkey_valid = true; for (i = 0; i < ARRAY_SIZE(bt_smp_pool); i++) { diff --git a/net/bluetooth/smp.h b/net/bluetooth/smp.h index 854f9a00765..3dc4d5c6b67 100644 --- a/net/bluetooth/smp.h +++ b/net/bluetooth/smp.h @@ -137,7 +137,7 @@ void bt_smp_update_keys(struct bt_conn *conn); bool bt_smp_get_tk(struct bt_conn *conn, uint8_t *tk); void bt_smp_dhkey_ready(const uint8_t *dhkey); -void bt_smp_pkey_ready(void); +void bt_smp_pkey_ready(const uint8_t *pkey); int bt_smp_init(void);