zephyr/subsys/bluetooth/host/settings.h
Théo Battrel 37cac7f2e2 Bluetooth: Host: Use custom API for Bluetooth settings
This commit wrap the `settings_set_one` and `settings_delete` functions
in `bt_settings_store_one` and `bt_settings_delete`. By doing that the
Bluetooth settings can be managed in a single place.

This commit also introduce a new API to manage Bluetooth storage with
`bt_settings_store_*` and `bt_settings_delete_*` functions. Each
Bluetooth settings key have their own store and delete functions. Doing
that so custom behavior for key can be done if necessary.

This change is motivated by a need of keeping track of different
persistently stored settings inside the Bluetooth subsystem. This will
allow a better management of the settings that the Bluetooth subsystem
is responsible of.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-06-17 07:58:07 -04:00

62 lines
2.3 KiB
C

/*
* Copyright (c) 2018 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/settings/settings.h>
/* Max settings key length (with all components) */
#define BT_SETTINGS_KEY_MAX 36
/* Base64-encoded string buffer size of in_size bytes */
#define BT_SETTINGS_SIZE(in_size) ((((((in_size) - 1) / 3) * 4) + 4) + 1)
#define BT_SETTINGS_DEFINE(_hname, _subtree, _set, _commit) \
SETTINGS_STATIC_HANDLER_DEFINE(bt_##_hname, "bt/" _subtree, NULL, _set, _commit, NULL)
#define ID_DATA_LEN(array) (bt_dev.id_count * sizeof(array[0]))
int bt_settings_store(const char *key, uint8_t id, const bt_addr_le_t *addr, const void *value,
size_t val_len);
int bt_settings_delete(const char *key, uint8_t id, const bt_addr_le_t *addr);
/* Helpers for keys containing a bdaddr */
void bt_settings_encode_key(char *path, size_t path_size, const char *subsys,
const bt_addr_le_t *addr, const char *key);
int bt_settings_decode_key(const char *key, bt_addr_le_t *addr);
void bt_settings_save_id(void);
int bt_settings_init(void);
int bt_settings_store_sc(uint8_t id, const bt_addr_le_t *addr, const void *value, size_t val_len);
int bt_settings_delete_sc(uint8_t id, const bt_addr_le_t *addr);
int bt_settings_store_cf(uint8_t id, const bt_addr_le_t *addr, const void *value, size_t val_len);
int bt_settings_delete_cf(uint8_t id, const bt_addr_le_t *addr);
int bt_settings_store_ccc(uint8_t id, const bt_addr_le_t *addr, const void *value, size_t val_len);
int bt_settings_delete_ccc(uint8_t id, const bt_addr_le_t *addr);
int bt_settings_store_hash(const void *value, size_t val_len);
int bt_settings_delete_hash(void);
int bt_settings_store_name(const void *value, size_t val_len);
int bt_settings_delete_name(void);
int bt_settings_store_appearance(const void *value, size_t val_len);
int bt_settings_delete_appearance(void);
int bt_settings_store_id(void);
int bt_settings_delete_id(void);
int bt_settings_store_irk(void);
int bt_settings_delete_irk(void);
int bt_settings_store_link_key(const bt_addr_le_t *addr, const void *value, size_t val_len);
int bt_settings_delete_link_key(const bt_addr_le_t *addr);
int bt_settings_store_keys(uint8_t id, const bt_addr_le_t *addr, const void *value, size_t val_len);
int bt_settings_delete_keys(uint8_t id, const bt_addr_le_t *addr);