86 lines
1.9 KiB
C
86 lines
1.9 KiB
C
/* keys_br.c - Bluetooth BR/EDR key handling */
|
|
|
|
/*
|
|
* Copyright (c) 2015-2016 Intel Corporation
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <zephyr.h>
|
|
#include <string.h>
|
|
#include <atomic.h>
|
|
#include <misc/util.h>
|
|
#include <misc/nano_work.h>
|
|
|
|
#include <bluetooth/log.h>
|
|
#include <bluetooth/bluetooth.h>
|
|
#include <bluetooth/conn.h>
|
|
#include <bluetooth/hci.h>
|
|
|
|
#include "hci_core.h"
|
|
#include "keys.h"
|
|
|
|
#if !defined(CONFIG_BLUETOOTH_DEBUG_KEYS)
|
|
#undef BT_DBG
|
|
#define BT_DBG(fmt, ...)
|
|
#endif
|
|
|
|
static struct bt_keys_link_key key_pool[CONFIG_BLUETOOTH_MAX_PAIRED];
|
|
|
|
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));
|
|
|
|
memset(link_key, 0, sizeof(*link_key));
|
|
}
|