Bluetooth: Move key handling to separate files
In preparation of adding more key support and to not bloat hci_core.c prepare a new .c file for the key management code. Change-Id: I5129a7a3a5d495a299f75e4e669253446a276142 Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
5dd8fd7f91
commit
384533912d
6 changed files with 146 additions and 71 deletions
|
@ -3,6 +3,7 @@ obj-y = att.o \
|
|||
conn.o \
|
||||
gatt.o \
|
||||
hci_core.o \
|
||||
keys.o \
|
||||
l2cap.o \
|
||||
smp.o \
|
||||
uuid.o
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include <bluetooth/hci.h>
|
||||
|
||||
#include "hci_core.h"
|
||||
#include "keys.h"
|
||||
#include "conn.h"
|
||||
#include "l2cap.h"
|
||||
|
||||
|
@ -67,8 +68,6 @@ static nano_context_id_t cmd_rx_fiber_id;
|
|||
|
||||
static struct bt_dev dev;
|
||||
|
||||
static struct bt_keys key_list[CONFIG_BLUETOOTH_MAX_PAIRED];
|
||||
|
||||
#if defined(CONFIG_BLUETOOTH_DEBUG)
|
||||
const char *bt_addr_str(const bt_addr_t *addr)
|
||||
{
|
||||
|
@ -115,59 +114,6 @@ const char *bt_addr_le_str(const bt_addr_le_t *addr)
|
|||
}
|
||||
#endif /* CONFIG_BLUETOOTH_DEBUG */
|
||||
|
||||
struct bt_keys *bt_keys_create(const bt_addr_le_t *addr)
|
||||
{
|
||||
struct bt_keys *keys;
|
||||
int i;
|
||||
|
||||
BT_DBG("%s\n", bt_addr_le_str(addr));
|
||||
|
||||
keys = bt_keys_find(addr);
|
||||
if (keys) {
|
||||
return keys;
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(key_list); i++) {
|
||||
keys = &key_list[i];
|
||||
|
||||
if (!bt_addr_le_cmp(&keys->addr, BT_ADDR_LE_ANY)) {
|
||||
bt_addr_le_copy(&keys->addr, addr);
|
||||
BT_DBG("created keys %p\n", keys);
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
|
||||
BT_DBG("no match\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct bt_keys *bt_keys_find(const bt_addr_le_t *addr)
|
||||
{
|
||||
int i;
|
||||
|
||||
BT_DBG("%s\n", bt_addr_le_str(addr));
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(key_list); i++) {
|
||||
struct bt_keys *keys = &key_list[i];
|
||||
|
||||
if (!bt_addr_le_cmp(&keys->addr, addr)) {
|
||||
BT_DBG("found keys %p\n", keys);
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
|
||||
BT_DBG("no match\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void bt_keys_clear(struct bt_keys *keys)
|
||||
{
|
||||
BT_DBG("keys %p\n", keys);
|
||||
memset(keys, 0, sizeof(*keys));
|
||||
}
|
||||
|
||||
struct bt_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
|
||||
{
|
||||
struct bt_hci_cmd_hdr *hdr;
|
||||
|
|
|
@ -139,22 +139,6 @@ static inline bool bt_addr_le_is_identity(const bt_addr_le_t *addr)
|
|||
return false;
|
||||
}
|
||||
|
||||
struct bt_ltk {
|
||||
uint64_t rand;
|
||||
uint16_t ediv;
|
||||
uint8_t val[16];
|
||||
};
|
||||
|
||||
struct bt_keys {
|
||||
bt_addr_le_t addr;
|
||||
|
||||
struct bt_ltk slave_ltk;
|
||||
};
|
||||
|
||||
struct bt_keys *bt_keys_create(const bt_addr_le_t *addr);
|
||||
struct bt_keys *bt_keys_find(const bt_addr_le_t *addr);
|
||||
void bt_keys_clear(struct bt_keys *keys);
|
||||
|
||||
struct bt_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len);
|
||||
int bt_hci_cmd_send(uint16_t opcode, struct bt_buf *buf);
|
||||
int bt_hci_cmd_send_sync(uint16_t opcode, struct bt_buf *buf,
|
||||
|
|
96
net/bluetooth/keys.c
Normal file
96
net/bluetooth/keys.c
Normal file
|
@ -0,0 +1,96 @@
|
|||
/* keys.c - Bluetooth key handling */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015 Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1) Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2) Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3) Neither the name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <nanokernel.h>
|
||||
#include <misc/util.h>
|
||||
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/hci.h>
|
||||
|
||||
#include "hci_core.h"
|
||||
#include "keys.h"
|
||||
|
||||
static struct bt_keys key_list[CONFIG_BLUETOOTH_MAX_PAIRED];
|
||||
|
||||
struct bt_keys *bt_keys_create(const bt_addr_le_t *addr)
|
||||
{
|
||||
struct bt_keys *keys;
|
||||
int i;
|
||||
|
||||
BT_DBG("%s\n", bt_addr_le_str(addr));
|
||||
|
||||
keys = bt_keys_find(addr);
|
||||
if (keys) {
|
||||
return keys;
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(key_list); i++) {
|
||||
keys = &key_list[i];
|
||||
|
||||
if (!bt_addr_le_cmp(&keys->addr, BT_ADDR_LE_ANY)) {
|
||||
bt_addr_le_copy(&keys->addr, addr);
|
||||
BT_DBG("created keys %p\n", keys);
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
|
||||
BT_DBG("no match\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct bt_keys *bt_keys_find(const bt_addr_le_t *addr)
|
||||
{
|
||||
int i;
|
||||
|
||||
BT_DBG("%s\n", bt_addr_le_str(addr));
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(key_list); i++) {
|
||||
struct bt_keys *keys = &key_list[i];
|
||||
|
||||
if (!bt_addr_le_cmp(&keys->addr, addr)) {
|
||||
BT_DBG("found keys %p\n", keys);
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
|
||||
BT_DBG("no match\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void bt_keys_clear(struct bt_keys *keys)
|
||||
{
|
||||
BT_DBG("keys %p\n", keys);
|
||||
memset(keys, 0, sizeof(*keys));
|
||||
}
|
47
net/bluetooth/keys.h
Normal file
47
net/bluetooth/keys.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* keys.h - Bluetooth key handling */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015 Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1) Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2) Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3) Neither the name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
struct bt_ltk {
|
||||
uint64_t rand;
|
||||
uint16_t ediv;
|
||||
uint8_t val[16];
|
||||
};
|
||||
|
||||
struct bt_keys {
|
||||
bt_addr_le_t addr;
|
||||
|
||||
struct bt_ltk slave_ltk;
|
||||
};
|
||||
|
||||
struct bt_keys *bt_keys_create(const bt_addr_le_t *addr);
|
||||
struct bt_keys *bt_keys_find(const bt_addr_le_t *addr);
|
||||
void bt_keys_clear(struct bt_keys *keys);
|
|
@ -44,6 +44,7 @@
|
|||
#include <bluetooth/bluetooth.h>
|
||||
|
||||
#include "hci_core.h"
|
||||
#include "keys.h"
|
||||
#include "conn.h"
|
||||
#include "l2cap.h"
|
||||
#include "smp.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue