1 /*
2  * Copyright (c) 2018 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /* Pending storage actions. */
8 enum bt_mesh_settings_flag {
9 	BT_MESH_SETTINGS_RPL_PENDING,
10 	BT_MESH_SETTINGS_NET_KEYS_PENDING,
11 	BT_MESH_SETTINGS_APP_KEYS_PENDING,
12 	BT_MESH_SETTINGS_NET_PENDING,
13 	BT_MESH_SETTINGS_IV_PENDING,
14 	BT_MESH_SETTINGS_SEQ_PENDING,
15 	BT_MESH_SETTINGS_HB_PUB_PENDING,
16 	BT_MESH_SETTINGS_CFG_PENDING,
17 	BT_MESH_SETTINGS_MOD_PENDING,
18 	BT_MESH_SETTINGS_VA_PENDING,
19 	BT_MESH_SETTINGS_CDB_PENDING,
20 	BT_MESH_SETTINGS_SRPL_PENDING,
21 	BT_MESH_SETTINGS_SSEQ_PENDING,
22 	BT_MESH_SETTINGS_COMP_PENDING,
23 	BT_MESH_SETTINGS_DEV_KEY_CAND_PENDING,
24 
25 	BT_MESH_SETTINGS_FLAG_COUNT,
26 };
27 
28 #ifdef CONFIG_BT_SETTINGS
29 #define BT_MESH_SETTINGS_DEFINE(_hname, _subtree, _set)                                            \
30 	static int pre_##_set(const char *name, size_t len_rd, settings_read_cb read_cb,           \
31 			      void *cb_arg)                                                        \
32 	{                                                                                          \
33 		if (!atomic_test_bit(bt_mesh.flags, BT_MESH_INIT)) {                               \
34 			return 0;                                                                  \
35 		}                                                                                  \
36 		return _set(name, len_rd, read_cb, cb_arg);                                        \
37 	}                                                                                          \
38 	SETTINGS_STATIC_HANDLER_DEFINE(bt_mesh_##_hname, "bt/mesh/" _subtree, NULL, pre_##_set,    \
39 				       NULL, NULL)
40 #else
41 /* Declaring non static settings handler helps avoid unnecessary ifdefs
42  * as well as unused function warning. Since the declared handler structure is
43  * unused, linker will discard it.
44  */
45 #define BT_MESH_SETTINGS_DEFINE(_hname, _subtree, _set)\
46 	const struct settings_handler settings_handler_bt_mesh_ ## _hname = {\
47 		.h_set = _set,						     \
48 	}
49 #endif
50 
51 void bt_mesh_settings_init(void);
52 void bt_mesh_settings_store_schedule(enum bt_mesh_settings_flag flag);
53 void bt_mesh_settings_store_cancel(enum bt_mesh_settings_flag flag);
54 void bt_mesh_settings_store_pending(void);
55 int bt_mesh_settings_set(settings_read_cb read_cb, void *cb_arg,
56 			 void *out, size_t read_len);
57