2016-04-02 02:44:38 +08:00
|
|
|
/** @file
|
|
|
|
* @brief Bluetooth subsystem persistent storage APIs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 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.
|
|
|
|
*/
|
|
|
|
#ifndef __BT_STORAGE_H
|
|
|
|
#define __BT_STORAGE_H
|
|
|
|
|
2016-05-17 00:54:24 +08:00
|
|
|
/**
|
|
|
|
* @brief Persistent Storage
|
|
|
|
* @defgroup bt_storage Persistent Storage
|
|
|
|
* @ingroup bluetooth
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2016-04-02 02:44:38 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <bluetooth/bluetooth.h>
|
|
|
|
#include <bluetooth/hci.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Well known storage keys */
|
|
|
|
enum {
|
2016-10-05 04:00:35 +08:00
|
|
|
/** Identity Address.
|
|
|
|
* Type: bt_addr_le_t (7 bytes)
|
|
|
|
*/
|
2016-07-18 17:32:42 +08:00
|
|
|
BT_STORAGE_ID_ADDR,
|
2016-10-05 04:00:35 +08:00
|
|
|
|
|
|
|
/** Local Identity Resolving Key.
|
|
|
|
* Type: uint8_t key[16]
|
|
|
|
*/
|
2016-07-18 17:32:42 +08:00
|
|
|
BT_STORAGE_LOCAL_IRK,
|
2016-10-05 04:00:56 +08:00
|
|
|
|
|
|
|
/** List of addresses of remote devices.
|
|
|
|
* Type: bt_addr_le_t addrs[n] (length is variable).
|
|
|
|
*
|
|
|
|
* This is only used for reading. Modification of the list happens
|
|
|
|
* implicitly by writing entries for each remote device. This value
|
|
|
|
* is only used with the local storage, i.e. NULL as the target
|
|
|
|
* bt_addr_le_t passed to the read callback.
|
|
|
|
*/
|
|
|
|
BT_STORAGE_ADDRESSES,
|
2016-10-07 21:13:58 +08:00
|
|
|
|
|
|
|
/** Slave Long Term Key for legacy pairing.
|
|
|
|
* Type: struct bt_storage_ltk
|
|
|
|
*/
|
|
|
|
BT_STORAGE_SLAVE_LTK,
|
|
|
|
|
|
|
|
/** Long Term Key for legacy pairing.
|
|
|
|
* Type: struct bt_storage_ltk
|
|
|
|
*/
|
|
|
|
BT_STORAGE_LTK,
|
|
|
|
|
|
|
|
/** Identity Resolving Key
|
|
|
|
* Type: uint8_t key[16]
|
|
|
|
*/
|
|
|
|
BT_STORAGE_IRK,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** LTK key flags */
|
|
|
|
enum {
|
|
|
|
/* Key has been generated with MITM protection */
|
|
|
|
BT_STORAGE_LTK_AUTHENTICATED = BIT(0),
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bt_storage_ltk {
|
|
|
|
uint8_t flags;
|
|
|
|
/* Encryption key size used to generate key */
|
|
|
|
uint8_t size;
|
|
|
|
uint16_t ediv;
|
|
|
|
uint8_t rand[8];
|
|
|
|
uint8_t val[16];
|
2016-04-02 02:44:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bt_storage {
|
|
|
|
/** Read the value of a key from storage.
|
|
|
|
*
|
|
|
|
* @param addr Remote address or NULL for local storage
|
|
|
|
* @param key BT_STORAGE_* key to read
|
|
|
|
* @param data Memory location to place the data
|
|
|
|
* @param length Maximum number of bytes to read
|
|
|
|
*
|
|
|
|
* @return Number of bytes read or negative error value on
|
|
|
|
* failure.
|
|
|
|
*/
|
|
|
|
ssize_t (*read)(const bt_addr_le_t *addr, uint16_t key,
|
|
|
|
void *data, size_t length);
|
|
|
|
|
|
|
|
/** Write the value of a key to storage.
|
|
|
|
*
|
|
|
|
* @param addr Remote address or NULL for local storage
|
|
|
|
* @param key BT_STORAGE_* key to write
|
|
|
|
* @param data Memory location of the data
|
|
|
|
* @param length Number of bytes to write
|
|
|
|
*
|
|
|
|
* @return Number of bytes written or negative error value on
|
|
|
|
* failure.
|
|
|
|
*/
|
|
|
|
ssize_t (*write)(const bt_addr_le_t *addr, uint16_t key,
|
|
|
|
const void *data, size_t length);
|
|
|
|
|
|
|
|
/** Clear all keys for a specific address
|
|
|
|
*
|
|
|
|
* @param addr Remote address, BT_ADDR_LE_ANY for all
|
|
|
|
* remote devices, or NULL for local storage.
|
|
|
|
*
|
|
|
|
* @return 0 on success or negative error value on failure.
|
|
|
|
*/
|
|
|
|
int (*clear)(const bt_addr_le_t *addr);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-10-05 04:00:35 +08:00
|
|
|
/** Register callbacks for storage handling.
|
|
|
|
*
|
|
|
|
* @param storage Callback struct.
|
|
|
|
*/
|
2016-05-30 20:05:28 +08:00
|
|
|
void bt_storage_register(const struct bt_storage *storage);
|
2016-04-02 02:44:38 +08:00
|
|
|
|
2016-04-05 15:33:13 +08:00
|
|
|
/** Clear all storage keys for a specific address
|
|
|
|
*
|
|
|
|
* @param addr Remote address, NULL for local storage or
|
|
|
|
* BT_ADDR_LE_ANY to clear all remote devices.
|
|
|
|
*
|
|
|
|
* @return 0 on success or negative error value on failure.
|
|
|
|
*/
|
2016-10-05 03:59:28 +08:00
|
|
|
int bt_storage_clear(const bt_addr_le_t *addr);
|
2016-04-05 15:33:13 +08:00
|
|
|
|
2016-04-02 02:44:38 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-05-17 00:54:24 +08:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2016-04-02 02:44:38 +08:00
|
|
|
#endif /* __BT_STORAGE_H */
|