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 	BT_MESH_SETTINGS_BRG_PENDING,
25 
26 	BT_MESH_SETTINGS_FLAG_COUNT,
27 };
28 
29 #ifdef CONFIG_BT_SETTINGS
30 #define BT_MESH_SETTINGS_DEFINE(_hname, _subtree, _set)                                            \
31 	static int pre_##_set(const char *name, size_t len_rd, settings_read_cb read_cb,           \
32 			      void *cb_arg)                                                        \
33 	{                                                                                          \
34 		if (!atomic_test_bit(bt_mesh.flags, BT_MESH_INIT)) {                               \
35 			return 0;                                                                  \
36 		}                                                                                  \
37 		return _set(name, len_rd, read_cb, cb_arg);                                        \
38 	}                                                                                          \
39 	SETTINGS_STATIC_HANDLER_DEFINE(bt_mesh_##_hname, "bt/mesh/" _subtree, NULL, pre_##_set,    \
40 				       NULL, NULL)
41 #else
42 /* Declaring non static settings handler helps avoid unnecessary ifdefs
43  * as well as unused function warning. Since the declared handler structure is
44  * unused, linker will discard it.
45  */
46 #define BT_MESH_SETTINGS_DEFINE(_hname, _subtree, _set)\
47 	const struct settings_handler settings_handler_bt_mesh_ ## _hname = {\
48 		.h_set = _set,						     \
49 	}
50 #endif
51 
52 void bt_mesh_settings_init(void);
53 void bt_mesh_settings_store_schedule(enum bt_mesh_settings_flag flag);
54 void bt_mesh_settings_store_cancel(enum bt_mesh_settings_flag flag);
55 void bt_mesh_settings_store_pending(void);
56 int bt_mesh_settings_set(settings_read_cb read_cb, void *cb_arg,
57 			 void *out, size_t read_len);
58