Bluetooth: Mesh: Store priv proxy in sep entry
Stores persistent on-demand private GATT proxy state in separate settings entry. This is implemented to avoid issues related to backwards compatibility between device firmware updates. Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
This commit is contained in:
parent
cf8301d01e
commit
6559de3238
3 changed files with 75 additions and 12 deletions
|
@ -16,6 +16,7 @@
|
||||||
#include "friend.h"
|
#include "friend.h"
|
||||||
#include "adv.h"
|
#include "adv.h"
|
||||||
#include "cfg.h"
|
#include "cfg.h"
|
||||||
|
#include "od_priv_proxy.h"
|
||||||
#include "priv_beacon.h"
|
#include "priv_beacon.h"
|
||||||
|
|
||||||
#define LOG_LEVEL CONFIG_BT_MESH_CFG_LOG_LEVEL
|
#define LOG_LEVEL CONFIG_BT_MESH_CFG_LOG_LEVEL
|
||||||
|
@ -31,9 +32,6 @@ struct cfg_val {
|
||||||
uint8_t gatt_proxy;
|
uint8_t gatt_proxy;
|
||||||
uint8_t frnd;
|
uint8_t frnd;
|
||||||
uint8_t default_ttl;
|
uint8_t default_ttl;
|
||||||
#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV)
|
|
||||||
uint8_t on_demand_state;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void bt_mesh_beacon_set(bool beacon)
|
void bt_mesh_beacon_set(bool beacon)
|
||||||
|
@ -157,9 +155,9 @@ int bt_mesh_od_priv_proxy_set(uint8_t on_demand_proxy)
|
||||||
bt_mesh.on_demand_state = on_demand_proxy;
|
bt_mesh.on_demand_state = on_demand_proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_BT_SETTINGS) &&
|
if (IS_ENABLED(CONFIG_BT_SETTINGS) && IS_ENABLED(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) &&
|
||||||
atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) {
|
atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) {
|
||||||
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_CFG_PENDING);
|
bt_mesh_od_priv_proxy_srv_store_schedule();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -449,9 +447,6 @@ static int cfg_set(const char *name, size_t len_rd,
|
||||||
bt_mesh_gatt_proxy_set(cfg.gatt_proxy);
|
bt_mesh_gatt_proxy_set(cfg.gatt_proxy);
|
||||||
bt_mesh_friend_set(cfg.frnd);
|
bt_mesh_friend_set(cfg.frnd);
|
||||||
bt_mesh_default_ttl_set(cfg.default_ttl);
|
bt_mesh_default_ttl_set(cfg.default_ttl);
|
||||||
#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV)
|
|
||||||
bt_mesh_od_priv_proxy_set(cfg.on_demand_state);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LOG_DBG("Restored configuration state");
|
LOG_DBG("Restored configuration state");
|
||||||
|
|
||||||
|
@ -484,10 +479,6 @@ static void store_pending_cfg(void)
|
||||||
val.gatt_proxy = bt_mesh_gatt_proxy_get();
|
val.gatt_proxy = bt_mesh_gatt_proxy_get();
|
||||||
val.frnd = bt_mesh_friend_get();
|
val.frnd = bt_mesh_friend_get();
|
||||||
val.default_ttl = bt_mesh_default_ttl_get();
|
val.default_ttl = bt_mesh_default_ttl_get();
|
||||||
#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV)
|
|
||||||
val.on_demand_state = bt_mesh_od_priv_proxy_get();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
err = settings_save_one("bt/mesh/Cfg", &val, sizeof(val));
|
err = settings_save_one("bt/mesh/Cfg", &val, sizeof(val));
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
7
subsys/bluetooth/mesh/od_priv_proxy.h
Normal file
7
subsys/bluetooth/mesh/od_priv_proxy.h
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
void bt_mesh_od_priv_proxy_srv_store_schedule(void);
|
|
@ -9,11 +9,28 @@
|
||||||
#include "access.h"
|
#include "access.h"
|
||||||
#include "cfg.h"
|
#include "cfg.h"
|
||||||
#include "foundation.h"
|
#include "foundation.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
#define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL
|
#define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
LOG_MODULE_REGISTER(bt_mesh_od_priv_proxy_srv);
|
LOG_MODULE_REGISTER(bt_mesh_od_priv_proxy_srv);
|
||||||
|
|
||||||
|
|
||||||
|
static struct bt_mesh_model *od_priv_proxy_srv;
|
||||||
|
static uint8_t on_demand_state;
|
||||||
|
|
||||||
|
static int od_priv_proxy_store(bool delete)
|
||||||
|
{
|
||||||
|
if (!IS_ENABLED(CONFIG_BT_SETTINGS)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const void *data = delete ? NULL : &on_demand_state;
|
||||||
|
size_t len = delete ? 0 : sizeof(uint8_t);
|
||||||
|
|
||||||
|
return bt_mesh_model_data_store(od_priv_proxy_srv, false, "pp", data, len);
|
||||||
|
}
|
||||||
|
|
||||||
static int proxy_status_rsp(struct bt_mesh_model *mod,
|
static int proxy_status_rsp(struct bt_mesh_model *mod,
|
||||||
struct bt_mesh_msg_ctx *ctx)
|
struct bt_mesh_msg_ctx *ctx)
|
||||||
{
|
{
|
||||||
|
@ -64,6 +81,8 @@ const struct bt_mesh_model_op _bt_mesh_od_priv_proxy_srv_op[] = {
|
||||||
|
|
||||||
static int od_priv_proxy_srv_init(struct bt_mesh_model *mod)
|
static int od_priv_proxy_srv_init(struct bt_mesh_model *mod)
|
||||||
{
|
{
|
||||||
|
od_priv_proxy_srv = mod;
|
||||||
|
|
||||||
struct bt_mesh_model *priv_beacon_srv = bt_mesh_model_find(
|
struct bt_mesh_model *priv_beacon_srv = bt_mesh_model_find(
|
||||||
bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_PRIV_BEACON_SRV);
|
bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_PRIV_BEACON_SRV);
|
||||||
struct bt_mesh_model *sol_pdu_rpl_srv = bt_mesh_model_find(
|
struct bt_mesh_model *sol_pdu_rpl_srv = bt_mesh_model_find(
|
||||||
|
@ -89,6 +108,52 @@ static int od_priv_proxy_srv_init(struct bt_mesh_model *mod)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void od_priv_proxy_srv_reset(struct bt_mesh_model *model)
|
||||||
|
{
|
||||||
|
on_demand_state = 0;
|
||||||
|
od_priv_proxy_store(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_BT_SETTINGS
|
||||||
|
static int od_priv_proxy_srv_settings_set(struct bt_mesh_model *model, const char *name,
|
||||||
|
size_t len_rd, settings_read_cb read_cb, void *cb_data)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if (len_rd == 0) {
|
||||||
|
LOG_DBG("Cleared configuration state");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = bt_mesh_settings_set(read_cb, cb_data, &on_demand_state, sizeof(uint8_t));
|
||||||
|
if (err) {
|
||||||
|
LOG_ERR("Failed to set OD private proxy state");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
bt_mesh_od_priv_proxy_set(on_demand_state);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void od_priv_proxy_srv_pending_store(struct bt_mesh_model *model)
|
||||||
|
{
|
||||||
|
on_demand_state = bt_mesh_od_priv_proxy_get();
|
||||||
|
od_priv_proxy_store(false);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
const struct bt_mesh_model_cb _bt_mesh_od_priv_proxy_srv_cb = {
|
const struct bt_mesh_model_cb _bt_mesh_od_priv_proxy_srv_cb = {
|
||||||
.init = od_priv_proxy_srv_init,
|
.init = od_priv_proxy_srv_init,
|
||||||
|
.reset = od_priv_proxy_srv_reset,
|
||||||
|
#ifdef CONFIG_BT_SETTINGS
|
||||||
|
.settings_set = od_priv_proxy_srv_settings_set,
|
||||||
|
.pending_store = od_priv_proxy_srv_pending_store,
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void bt_mesh_od_priv_proxy_srv_store_schedule(void)
|
||||||
|
{
|
||||||
|
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
|
||||||
|
bt_mesh_model_data_store_schedule(od_priv_proxy_srv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue