2016-08-08 22:40:30 +08:00
|
|
|
/* keys_br.c - Bluetooth BR/EDR key handling */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015-2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-08-08 22:40:30 +08:00
|
|
|
*/
|
|
|
|
|
2016-10-21 18:04:56 +08:00
|
|
|
#include <zephyr.h>
|
2016-08-08 22:40:30 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <atomic.h>
|
|
|
|
#include <misc/util.h>
|
|
|
|
|
|
|
|
#include <bluetooth/bluetooth.h>
|
|
|
|
#include <bluetooth/conn.h>
|
|
|
|
#include <bluetooth/hci.h>
|
|
|
|
|
2017-08-09 14:21:11 +08:00
|
|
|
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_KEYS)
|
2017-05-10 22:27:16 +08:00
|
|
|
#include "common/log.h"
|
|
|
|
|
2016-08-08 22:40:30 +08:00
|
|
|
#include "hci_core.h"
|
|
|
|
#include "keys.h"
|
|
|
|
|
2017-08-09 14:21:11 +08:00
|
|
|
static struct bt_keys_link_key key_pool[CONFIG_BT_MAX_PAIRED];
|
2016-08-08 22:40:30 +08:00
|
|
|
|
|
|
|
struct bt_keys_link_key *bt_keys_find_link_key(const bt_addr_t *addr)
|
|
|
|
{
|
|
|
|
struct bt_keys_link_key *key;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
BT_DBG("%s", bt_addr_str(addr));
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(key_pool); i++) {
|
|
|
|
key = &key_pool[i];
|
|
|
|
|
|
|
|
if (!bt_addr_cmp(&key->addr, addr)) {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bt_keys_link_key *bt_keys_get_link_key(const bt_addr_t *addr)
|
|
|
|
{
|
|
|
|
struct bt_keys_link_key *key;
|
|
|
|
|
|
|
|
key = bt_keys_find_link_key(addr);
|
|
|
|
if (key) {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
key = bt_keys_find_link_key(BT_ADDR_ANY);
|
|
|
|
if (key) {
|
|
|
|
bt_addr_copy(&key->addr, addr);
|
|
|
|
BT_DBG("created %p for %s", key, bt_addr_str(addr));
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
BT_DBG("unable to create link key for %s", bt_addr_str(addr));
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bt_keys_link_key_clear(struct bt_keys_link_key *link_key)
|
|
|
|
{
|
|
|
|
BT_DBG("%s", bt_addr_str(&link_key->addr));
|
|
|
|
|
2018-09-12 10:09:03 +08:00
|
|
|
(void)memset(link_key, 0, sizeof(*link_key));
|
2016-08-08 22:40:30 +08:00
|
|
|
}
|
2016-11-05 03:34:05 +08:00
|
|
|
|
|
|
|
void bt_keys_link_key_clear_addr(const bt_addr_t *addr)
|
|
|
|
{
|
|
|
|
struct bt_keys_link_key *key;
|
|
|
|
|
|
|
|
if (!addr) {
|
2018-09-12 10:09:03 +08:00
|
|
|
(void)memset(key_pool, 0, sizeof(key_pool));
|
2016-11-05 03:34:05 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
key = bt_keys_find_link_key(addr);
|
|
|
|
if (key) {
|
|
|
|
bt_keys_link_key_clear(key);
|
|
|
|
}
|
|
|
|
}
|