From ef703e1317f3e99db76efee6efcf0cec3562d79d Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Wed, 15 Jul 2015 16:05:10 +0300 Subject: [PATCH] Bluetooth: Add local and remote CSRK keys Add local and remote Connection Signature Resolving Keys and helper functions. Change-Id: I63af2e566dccc6ffb5397d28bde6f04bc78b93b1 Signed-off-by: Andrei Emeltchenko --- net/bluetooth/keys.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ net/bluetooth/keys.h | 13 ++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/keys.c b/net/bluetooth/keys.c index 6c025be5efb..ba204ac0430 100644 --- a/net/bluetooth/keys.c +++ b/net/bluetooth/keys.c @@ -55,6 +55,8 @@ static struct bt_keys key_pool[CONFIG_BLUETOOTH_MAX_PAIRED]; static struct bt_keys *ltks; static struct bt_keys *slave_ltks; static struct bt_keys *irks; +static struct bt_keys *local_csrks; +static struct bt_keys *remote_csrks; struct bt_keys *bt_keys_get_addr(const bt_addr_le_t *addr) { @@ -119,6 +121,26 @@ void bt_keys_clear(struct bt_keys *keys, int type) keys->keys &= ~BT_KEYS_IRK; } + if (((type & keys->keys) & BT_KEYS_LOCAL_CSRK)) { + bt_keys_foreach(&local_csrks, cur, local_csrk.next) { + if (*cur == keys) { + *cur = (*cur)->local_csrk.next; + break; + } + } + keys->keys &= ~BT_KEYS_LOCAL_CSRK; + } + + if (((type & keys->keys) & BT_KEYS_REMOTE_CSRK)) { + bt_keys_foreach(&remote_csrks, cur, remote_csrk.next) { + if (*cur == keys) { + *cur = (*cur)->remote_csrk.next; + break; + } + } + keys->keys &= ~BT_KEYS_REMOTE_CSRK; + } + if (!keys->keys) { memset(keys, 0, sizeof(*keys)); } @@ -152,6 +174,20 @@ struct bt_keys *bt_keys_find(int type, const bt_addr_le_t *addr) } } return *cur; + case BT_KEYS_LOCAL_CSRK: + bt_keys_foreach(&local_csrks, cur, local_csrk.next) { + if (!bt_addr_le_cmp(&(*cur)->addr, addr)) { + break; + } + } + return *cur; + case BT_KEYS_REMOTE_CSRK: + bt_keys_foreach(&remote_csrks, cur, remote_csrk.next) { + if (!bt_addr_le_cmp(&(*cur)->addr, addr)) { + break; + } + } + return *cur; default: return NULL; } @@ -176,6 +212,14 @@ void bt_keys_add_type(struct bt_keys *keys, int type) keys->irk.next = irks; irks = keys; break; + case BT_KEYS_LOCAL_CSRK: + keys->local_csrk.next = local_csrks; + local_csrks = keys; + break; + case BT_KEYS_REMOTE_CSRK: + keys->remote_csrk.next = remote_csrks; + remote_csrks = keys; + break; default: BT_ERR("Unknown key type %d\n", type); return; diff --git a/net/bluetooth/keys.h b/net/bluetooth/keys.h index b7ca0c454d1..3eedba1ad10 100644 --- a/net/bluetooth/keys.h +++ b/net/bluetooth/keys.h @@ -34,9 +34,12 @@ enum { BT_KEYS_SLAVE_LTK = (1 << 0), BT_KEYS_IRK = (1 << 1), BT_KEYS_LTK = (1 << 2), + BT_KEYS_LOCAL_CSRK = (1 << 3), + BT_KEYS_REMOTE_CSRK = (1 << 4), BT_KEYS_ALL = (BT_KEYS_SLAVE_LTK | BT_KEYS_IRK | \ - BT_KEYS_LTK), + BT_KEYS_LTK | BT_KEYS_LOCAL_CSRK | \ + BT_KEYS_REMOTE_CSRK), }; struct bt_ltk { @@ -52,6 +55,12 @@ struct bt_irk { struct bt_keys *next; }; +struct bt_csrk { + uint8_t val[16]; + uint32_t cnt; + struct bt_keys *next; +}; + struct bt_keys { bt_addr_le_t addr; int keys; @@ -59,6 +68,8 @@ struct bt_keys { struct bt_ltk slave_ltk; struct bt_ltk ltk; struct bt_irk irk; + struct bt_csrk local_csrk; + struct bt_csrk remote_csrk; }; struct bt_keys *bt_keys_get_addr(const bt_addr_le_t *addr);