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 <andrei.emeltchenko@intel.com>
This commit is contained in:
Andrei Emeltchenko 2015-07-15 16:05:10 +03:00 committed by Anas Nashif
parent a7de88f972
commit ef703e1317
2 changed files with 56 additions and 1 deletions

View File

@ -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;

View File

@ -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);