1 /*
2 * Copyright (c) 2021 Nordic Semiconductor
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "mesh_test.h"
8 #include <zephyr/bluetooth/mesh.h>
9 #include <zephyr/sys/reboot.h>
10 #include "mesh/net.h"
11 #include "mesh/app_keys.h"
12 #include "mesh/keys.h"
13 #include <bs_cmd_line.h>
14
15 #define LOG_MODULE_NAME test_persistence
16
17 #include <zephyr/logging/log.h>
18 LOG_MODULE_REGISTER(LOG_MODULE_NAME);
19
20 #define WAIT_TIME 60 /*seconds*/
21
22 static bool provisioner_ready;
23
24 extern const struct bt_mesh_comp comp;
25
26 struct test_va_t {
27 uint16_t addr;
28 uint8_t uuid[16];
29 };
30
31 struct test_appkey_t {
32 uint8_t idx;
33 uint8_t key[16];
34 };
35
36 #define TEST_PROV_ADDR 0x0001
37 #define TEST_ADDR 0x0123
38 static uint8_t test_prov_uuid[16] = { 0x6c, 0x69, 0x6e, 0x67, 0x61, 0xaa };
39 static uint8_t test_dev_uuid[16] = { 0x6c, 0x69, 0x6e, 0x67, 0x61, 0x6f };
40 static int test_ividx = 0x123456;
41 static uint8_t test_flags;
42 static uint8_t test_netkey_idx = 0x77;
43 static uint8_t test_netkey[16] = { 0xaa };
44 static uint8_t test_devkey[16] = { 0xdd };
45 static uint8_t test_prov_devkey[16] = { 0x11 };
46
47 #define TEST_GROUP_0 0xc001
48 #define TEST_GROUP_1 0xfab3
49
50 #define TEST_VA_0_ADDR 0xb6f0
51 #define TEST_VA_0_UUID (uint8_t[16]) { 0xca, 0xcd, 0x13, 0xbd, 0x54, 0xfe, 0x43, 0xed, \
52 0x12, 0x3d, 0xa3, 0xe3, 0xb9, 0x03, 0x70, 0xaa }
53 #define TEST_VA_1_ADDR 0x8700
54 #define TEST_VA_1_UUID (uint8_t[16]) { 0xdf, 0xca, 0xa3, 0x54, 0x23, 0xfa, 0x33, 0xed, \
55 0x1a, 0xbe, 0xa0, 0xaa, 0xbd, 0xfa, 0x0f, 0xaf }
56 #define TEST_VA_1_ADDR_COL 0x8700
57 #define TEST_VA_1_UUID_COL (uint8_t[16]) { 0x01, 0xcc, 0x74, 0x51, 0x71, 0x9e, 0x56, 0x71, \
58 0x5b, 0x8a, 0x18, 0xaf, 0x13, 0x86, 0x0e, 0x4a }
59
60 #define TEST_APPKEY_0_IDX 0x12
61 #define TEST_APPKEY_0_KEY { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \
62 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }
63 #define TEST_APPKEY_1_IDX 0x43
64 #define TEST_APPKEY_1_KEY { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \
65 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f }
66
67 #define TEST_MOD_PUB_PARAMS { \
68 .addr = TEST_ADDR, \
69 .uuid = NULL, \
70 .app_idx = TEST_APPKEY_0_IDX, \
71 .cred_flag = true, \
72 .ttl = 5, \
73 .period = BT_MESH_PUB_PERIOD_10SEC(2), \
74 .transmit = BT_MESH_TRANSMIT(2, 20), \
75 }
76
77 #define TEST_VND_MOD_PUB_PARAMS { \
78 .addr = TEST_VA_0_ADDR, \
79 .uuid = TEST_VA_0_UUID, \
80 .app_idx = TEST_APPKEY_1_IDX, \
81 .cred_flag = true, \
82 .ttl = 5, \
83 .period = BT_MESH_PUB_PERIOD_10SEC(1), \
84 .transmit = BT_MESH_TRANSMIT(2, 20), \
85 }
86
87 #define TEST_MOD_PUB_PARAMS_2 { \
88 .addr = TEST_GROUP_1, \
89 .uuid = NULL, \
90 .app_idx = TEST_APPKEY_1_IDX, \
91 .cred_flag = false, \
92 .ttl = 3, \
93 .period = BT_MESH_PUB_PERIOD_10SEC(3), \
94 .transmit = BT_MESH_TRANSMIT(3, 20), \
95 }
96
97 #define TEST_VND_MOD_PUB_PARAMS_2 { \
98 .addr = TEST_VA_1_ADDR, \
99 .uuid = TEST_VA_1_UUID, \
100 .app_idx = TEST_APPKEY_0_IDX, \
101 .cred_flag = false, \
102 .ttl = 3, \
103 .period = BT_MESH_PUB_PERIOD_10SEC(2), \
104 .transmit = BT_MESH_TRANSMIT(3, 20), \
105 }
106
107 #define DISABLED_MOD_PUB_PARAMS { \
108 .addr = 0, \
109 .uuid = NULL, \
110 .app_idx = 0, \
111 .cred_flag = false, \
112 .ttl = 0, \
113 .period = 0, \
114 .transmit = 0, \
115 }
116
117 #define TEST_MOD_DATA_NAME "tmdata"
118 static uint8_t test_mod_data[] = { 0xfa, 0xff, 0xf4, 0x43 };
119 #define TEST_VND_MOD_DATA_NAME "vtmdata"
120 static uint8_t vnd_test_mod_data[] = { 0xad, 0xdf, 0x14, 0x53, 0x54, 0x1f };
121
122 struct access_cfg {
123 struct bt_mesh_cfg_cli_mod_pub pub_params;
124
125 size_t appkeys_count;
126 uint16_t appkeys[CONFIG_BT_MESH_MODEL_KEY_COUNT];
127
128 size_t subs_count;
129 uint16_t subs[CONFIG_BT_MESH_MODEL_GROUP_COUNT];
130
131 size_t mod_data_len;
132 };
133 static const struct access_cfg (*current_access_cfg)[2];
134 enum {
135 CONFIGURED,
136 NEW_SUBS,
137 NOT_CONFIGURED,
138 };
139 static const struct access_cfg access_cfgs[][2] = {
140 [CONFIGURED] = {
141 /* SIG model. */
142 {
143 .pub_params = TEST_MOD_PUB_PARAMS,
144 .appkeys_count = 2, .appkeys = { TEST_APPKEY_0_IDX, TEST_APPKEY_1_IDX },
145 .subs_count = 4, .subs = { TEST_GROUP_0, TEST_VA_0_ADDR, TEST_VA_1_ADDR,
146 TEST_VA_1_ADDR /* collision */ },
147 .mod_data_len = sizeof(test_mod_data),
148 },
149
150 /* Vendor model. */
151 {
152 .pub_params = TEST_VND_MOD_PUB_PARAMS,
153 .appkeys_count = 2, .appkeys = { TEST_APPKEY_0_IDX, TEST_APPKEY_1_IDX },
154 .subs_count = 4, .subs = { TEST_GROUP_0, TEST_VA_0_ADDR, TEST_VA_1_ADDR,
155 TEST_VA_1_ADDR /* collision */ },
156 .mod_data_len = sizeof(vnd_test_mod_data),
157 },
158 },
159
160 [NEW_SUBS] = {
161 /* SIG model. */
162 {
163 .pub_params = TEST_MOD_PUB_PARAMS_2,
164 .appkeys_count = 2, .appkeys = { TEST_APPKEY_0_IDX, TEST_APPKEY_1_IDX },
165 .subs_count = 1, .subs = { TEST_GROUP_0 },
166 .mod_data_len = sizeof(test_mod_data),
167 },
168
169 /* Vendor model. */
170 {
171 .pub_params = TEST_VND_MOD_PUB_PARAMS_2,
172 .appkeys_count = 2, .appkeys = { TEST_APPKEY_0_IDX, TEST_APPKEY_1_IDX },
173 .subs_count = 1, .subs = { TEST_VA_0_ADDR },
174 .mod_data_len = sizeof(vnd_test_mod_data),
175 },
176 },
177
178 [NOT_CONFIGURED] = {
179 /* SIG model. */
180 {
181 .pub_params = DISABLED_MOD_PUB_PARAMS,
182 .appkeys_count = 0, .appkeys = {},
183 .subs_count = 0, .subs = {},
184 .mod_data_len = 0,
185 },
186
187 /* Vendor model. */
188 {
189 .pub_params = DISABLED_MOD_PUB_PARAMS,
190 .appkeys_count = 0, .appkeys = {},
191 .subs_count = 0, .subs = {},
192 .mod_data_len = 0,
193 },
194 },
195 };
196
197 static const struct stack_cfg {
198 uint8_t beacon;
199 uint8_t ttl;
200 uint8_t gatt_proxy;
201 uint8_t friend;
202 uint8_t net_transmit;
203 struct {
204 enum bt_mesh_feat_state state;
205 uint8_t transmit;
206 } relay;
207 #ifdef CONFIG_BT_MESH_PRIV_BEACONS
208 uint8_t priv_beacon;
209 uint8_t priv_beacon_int;
210 uint8_t priv_beacon_gatt;
211 #endif
212 #ifdef CONFIG_BT_MESH_OD_PRIV_PROXY_SRV
213 uint8_t priv_proxy_val;
214 #endif
215 } stack_cfgs[] = {
216 {
217 .beacon = 1,
218 .ttl = 12,
219 .gatt_proxy = 1,
220 .friend = 1,
221 .net_transmit = BT_MESH_TRANSMIT(3, 20),
222 .relay = { .state = BT_MESH_FEATURE_ENABLED, .transmit = BT_MESH_TRANSMIT(2, 20) },
223 #ifdef CONFIG_BT_MESH_PRIV_BEACONS
224 .priv_beacon = 1,
225 .priv_beacon_int = 123,
226 .priv_beacon_gatt = 0,
227 #endif
228 #ifdef CONFIG_BT_MESH_OD_PRIV_PROXY_SRV
229 .priv_proxy_val = 10,
230 #endif
231 },
232 {
233 .beacon = 0,
234 .ttl = 0,
235 .gatt_proxy = 0,
236 .friend = 0,
237 .net_transmit = BT_MESH_TRANSMIT(1, 30),
238 .relay = { .state = BT_MESH_FEATURE_ENABLED, .transmit = BT_MESH_TRANSMIT(1, 10) },
239 #ifdef CONFIG_BT_MESH_PRIV_BEACONS
240 .priv_beacon = 1,
241 .priv_beacon_int = 100,
242 .priv_beacon_gatt = 1,
243 #endif
244 #ifdef CONFIG_BT_MESH_OD_PRIV_PROXY_SRV
245 .priv_proxy_val = 20,
246 #endif
247 },
248 };
249 static const struct stack_cfg *current_stack_cfg;
250
test_args_parse(int argc,char * argv[])251 static void test_args_parse(int argc, char *argv[])
252 {
253 char *access_cfg_str = NULL;
254 int32_t stack_cfg = -1;
255
256 bs_args_struct_t args_struct[] = {
257 {
258 .dest = &access_cfg_str,
259 .type = 's',
260 .name = "{configured, new-subs, not-configured}",
261 .option = "access-cfg",
262 .descript = ""
263 },
264 {
265 .dest = &stack_cfg,
266 .type = 'i',
267 .name = "{0, 1}",
268 .option = "stack-cfg",
269 .descript = ""
270 }
271 };
272
273 bs_args_parse_all_cmd_line(argc, argv, args_struct);
274
275 if (access_cfg_str != NULL) {
276 if (!strcmp(access_cfg_str, "configured")) {
277 current_access_cfg = &access_cfgs[CONFIGURED];
278 } else if (!strcmp(access_cfg_str, "new-subs")) {
279 current_access_cfg = &access_cfgs[NEW_SUBS];
280 } else if (!strcmp(access_cfg_str, "not-configured")) {
281 current_access_cfg = &access_cfgs[NOT_CONFIGURED];
282 }
283 }
284
285 if (stack_cfg >= 0 && stack_cfg < ARRAY_SIZE(stack_cfgs)) {
286 current_stack_cfg = &stack_cfgs[stack_cfg];
287 }
288 }
289
290 static struct k_sem prov_sem;
291
prov_complete(uint16_t net_idx,uint16_t addr)292 static void prov_complete(uint16_t net_idx, uint16_t addr)
293 {
294 LOG_INF("Device provisioning is complete, addr: %d", addr);
295 k_sem_give(&prov_sem);
296 }
297
device_reset(void)298 static void device_reset(void)
299 {
300 LOG_INF("Device is reset");
301 k_sem_give(&prov_sem);
302 }
303
unprovisioned_beacon(uint8_t uuid[16],bt_mesh_prov_oob_info_t oob_info,uint32_t * uri_hash)304 static void unprovisioned_beacon(uint8_t uuid[16], bt_mesh_prov_oob_info_t oob_info,
305 uint32_t *uri_hash)
306 {
307 static bool once;
308
309 /* Subnet may not be ready yet when provisioner receives a beacon. */
310 if (!provisioner_ready) {
311 LOG_INF("Provisioner is not ready yet");
312 return;
313 }
314
315 if (once) {
316 return;
317 }
318
319 once = !once;
320
321 ASSERT_OK(bt_mesh_provision_adv(uuid, test_netkey_idx, TEST_ADDR, 0));
322 }
323
prov_node_added(uint16_t net_idx,uint8_t uuid[16],uint16_t addr,uint8_t num_elem)324 static void prov_node_added(uint16_t net_idx, uint8_t uuid[16], uint16_t addr, uint8_t num_elem)
325 {
326 LOG_INF("Device 0x%04x provisioned", addr);
327 k_sem_give(&prov_sem);
328 }
329
check_mod_pub_params(const struct bt_mesh_cfg_cli_mod_pub * expected,const struct bt_mesh_cfg_cli_mod_pub * got)330 static void check_mod_pub_params(const struct bt_mesh_cfg_cli_mod_pub *expected,
331 const struct bt_mesh_cfg_cli_mod_pub *got)
332 {
333 ASSERT_EQUAL(expected->addr, got->addr);
334 ASSERT_EQUAL(expected->app_idx, got->app_idx);
335 ASSERT_EQUAL(expected->cred_flag, got->cred_flag);
336 ASSERT_EQUAL(expected->ttl, got->ttl);
337 ASSERT_EQUAL(expected->period, got->period);
338 ASSERT_EQUAL(expected->transmit, got->transmit);
339 }
340
test_model_settings_set(struct bt_mesh_model * model,const char * name,size_t len_rd,settings_read_cb read_cb,void * cb_arg)341 int test_model_settings_set(struct bt_mesh_model *model,
342 const char *name, size_t len_rd,
343 settings_read_cb read_cb, void *cb_arg)
344 {
345 uint8_t data[sizeof(test_mod_data)];
346 ssize_t result;
347
348 ASSERT_TRUE(name != NULL);
349 if (strncmp(name, TEST_MOD_DATA_NAME, strlen(TEST_MOD_DATA_NAME))) {
350 FAIL("Invalid entry name: [%s]", name);
351 }
352
353 settings_name_next(name, &name);
354 ASSERT_TRUE(name == NULL);
355
356 ASSERT_TRUE(current_access_cfg != NULL);
357 result = read_cb(cb_arg, &data, sizeof(data));
358 ASSERT_EQUAL((*current_access_cfg)[0].mod_data_len, result);
359
360 if (memcmp(data, test_mod_data, (*current_access_cfg)[0].mod_data_len)) {
361 FAIL("Incorrect data restored");
362 }
363
364 return 0;
365 }
366
test_model_reset(struct bt_mesh_model * model)367 void test_model_reset(struct bt_mesh_model *model)
368 {
369 ASSERT_OK(bt_mesh_model_data_store(test_model, false, TEST_MOD_DATA_NAME, NULL, 0));
370 }
371
test_vnd_model_settings_set(struct bt_mesh_model * model,const char * name,size_t len_rd,settings_read_cb read_cb,void * cb_arg)372 int test_vnd_model_settings_set(struct bt_mesh_model *model,
373 const char *name, size_t len_rd,
374 settings_read_cb read_cb, void *cb_arg)
375 {
376 uint8_t data[sizeof(vnd_test_mod_data)];
377 ssize_t result;
378
379 ASSERT_TRUE(name != NULL);
380 if (strncmp(name, TEST_VND_MOD_DATA_NAME, strlen(TEST_VND_MOD_DATA_NAME))) {
381 FAIL("Invalid entry name: %s", name);
382 }
383
384 settings_name_next(name, &name);
385 ASSERT_TRUE(name == NULL);
386
387 ASSERT_TRUE(current_access_cfg != NULL);
388 result = read_cb(cb_arg, &data, sizeof(data));
389 ASSERT_EQUAL((*current_access_cfg)[1].mod_data_len, result);
390
391 if (memcmp(data, vnd_test_mod_data, (*current_access_cfg)[1].mod_data_len)) {
392 FAIL("Incorrect data restored");
393 }
394
395 return 0;
396 }
397
test_vnd_model_reset(struct bt_mesh_model * model)398 void test_vnd_model_reset(struct bt_mesh_model *model)
399 {
400 ASSERT_OK(bt_mesh_model_data_store(test_vnd_model, true, TEST_VND_MOD_DATA_NAME, NULL, 0));
401 }
402
device_setup(void)403 static void device_setup(void)
404 {
405 static struct bt_mesh_prov prov = {
406 .uuid = test_dev_uuid,
407 .complete = prov_complete,
408 .reset = device_reset,
409 };
410
411 k_sem_init(&prov_sem, 0, 1);
412
413 bt_mesh_device_setup(&prov, &comp);
414 }
415
device_setup_and_self_provision(void)416 static int device_setup_and_self_provision(void)
417 {
418 device_setup();
419
420 return bt_mesh_provision(test_netkey, test_netkey_idx, test_flags, test_ividx, TEST_ADDR,
421 test_devkey);
422 }
423
provisioner_setup(void)424 static void provisioner_setup(void)
425 {
426 static struct bt_mesh_prov prov = {
427 .uuid = test_prov_uuid,
428 .unprovisioned_beacon = unprovisioned_beacon,
429 .node_added = prov_node_added,
430 };
431 uint8_t primary_netkey[16] = { 0xad, 0xde, 0xfa, 0x32 };
432 struct bt_mesh_cdb_subnet *subnet;
433 uint8_t status;
434 int err;
435
436 k_sem_init(&prov_sem, 0, 1);
437
438 bt_mesh_device_setup(&prov, &comp);
439
440 ASSERT_OK(bt_mesh_cdb_create(primary_netkey));
441 ASSERT_OK(bt_mesh_provision(primary_netkey, 0, test_flags, test_ividx, TEST_PROV_ADDR,
442 test_prov_devkey));
443
444 /* Adding a subnet for test_netkey as it is not primary. */
445 subnet = bt_mesh_cdb_subnet_alloc(test_netkey_idx);
446 ASSERT_TRUE(subnet != NULL);
447 err = bt_mesh_cdb_subnet_key_import(subnet, 0, test_netkey);
448 if (err) {
449 FAIL("Unable to import test_netkey (err: %d)", err);
450 }
451 bt_mesh_cdb_subnet_store(subnet);
452
453 err = bt_mesh_cfg_cli_net_key_add(0, TEST_PROV_ADDR, test_netkey_idx, test_netkey, &status);
454 if (err || status) {
455 FAIL("Failed to add test_netkey (err: %d, status: %d)", err, status);
456 }
457
458 provisioner_ready = true;
459 }
460
test_provisioning_data_save(void)461 static void test_provisioning_data_save(void)
462 {
463 bt_mesh_test_cfg_set(NULL, WAIT_TIME);
464
465 if (device_setup_and_self_provision()) {
466 FAIL("Mesh setup failed. Settings should not be loaded.");
467 }
468
469 k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT));
470
471 PASS();
472 }
473
test_provisioning_data_load(void)474 static void test_provisioning_data_load(void)
475 {
476 /* In this test stack should boot as provisioned */
477 bt_mesh_test_cfg_set(NULL, WAIT_TIME);
478
479 if (device_setup_and_self_provision() != -EALREADY) {
480 FAIL("Device should boot up as already provisioned");
481 }
482
483 /* verify: */
484 /* explicitly verify that the keys resolves for a given addr and net_idx */
485 struct bt_mesh_msg_ctx ctx;
486 struct bt_mesh_net_tx tx = { .ctx = &ctx };
487 const struct bt_mesh_key *dkey;
488 uint8_t aid;
489 uint8_t net_key[16];
490 uint8_t dev_key[16];
491
492 tx.ctx->addr = TEST_ADDR;
493 tx.ctx->net_idx = test_netkey_idx;
494 tx.ctx->app_idx = BT_MESH_KEY_DEV_REMOTE; /* to resolve devkey */
495
496 int err = bt_mesh_keys_resolve(tx.ctx, &tx.sub, &dkey, &aid);
497
498 if (err) {
499 FAIL("Failed to resolve keys");
500 }
501
502 ASSERT_OK(bt_mesh_key_export(dev_key, dkey));
503 LOG_HEXDUMP_INF(dev_key, sizeof(dev_key), "Exported device key:");
504
505 if (memcmp(dev_key, test_devkey, sizeof(test_devkey))) {
506 FAIL("Resolved dev_key does not match");
507 }
508
509 ASSERT_OK(bt_mesh_key_export(net_key, &tx.sub->keys[0].net));
510 LOG_HEXDUMP_INF(net_key, sizeof(net_key), "Exported network key:");
511
512 if (memcmp(net_key, test_netkey, sizeof(test_netkey))) {
513 FAIL("Resolved raw value of the net_key does not match");
514 }
515
516 if (tx.sub->kr_phase != ((test_flags & 1) << 1)) {
517 FAIL("Incorrect KR phase loaded");
518 }
519
520 /* send TTL Get to verify Tx/Rx path works with loaded config */
521 uint8_t ttl;
522
523 err = bt_mesh_cfg_cli_ttl_get(test_netkey_idx, TEST_ADDR, &ttl);
524 if (err) {
525 FAIL("Failed to read ttl value");
526 }
527
528 /* verify IV index state */
529 if (bt_mesh.iv_index != test_ividx ||
530 bt_mesh.ivu_duration != 0 ||
531 atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)) {
532 FAIL("IV loading verification failed");
533 }
534
535 k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT));
536
537 PASS();
538 }
539
node_configure(void)540 static void node_configure(void)
541 {
542 int err;
543 uint8_t status;
544 uint16_t va;
545 struct bt_mesh_cfg_cli_mod_pub pub_params;
546
547 struct test_appkey_t test_appkeys[] = {
548 { .idx = TEST_APPKEY_0_IDX, .key = TEST_APPKEY_0_KEY },
549 { .idx = TEST_APPKEY_1_IDX, .key = TEST_APPKEY_1_KEY },
550 };
551
552 for (size_t i = 0; i < ARRAY_SIZE(test_appkeys); i++) {
553 err = bt_mesh_cfg_cli_app_key_add(test_netkey_idx, TEST_ADDR, test_netkey_idx,
554 test_appkeys[i].idx, test_appkeys[i].key, &status);
555 if (err || status) {
556 FAIL("AppKey add failed (err %d, status %u, i %d)", err, status, i);
557 }
558 }
559
560 /* SIG model. */
561 for (size_t i = 0; i < ARRAY_SIZE(test_appkeys); i++) {
562 err = bt_mesh_cfg_cli_mod_app_bind(test_netkey_idx, TEST_ADDR, TEST_ADDR,
563 test_appkeys[i].idx, TEST_MOD_ID, &status);
564 if (err || status) {
565 FAIL("Mod app bind failed (err %d, status %u, i %d)", err, status, i);
566 }
567 }
568
569 err = bt_mesh_cfg_cli_mod_sub_add(test_netkey_idx, TEST_ADDR, TEST_ADDR, TEST_GROUP_0,
570 TEST_MOD_ID, &status);
571 if (err || status) {
572 FAIL("Mod sub add failed (err %d, status %u)", err, status);
573 }
574
575 struct {
576 const uint8_t *uuid;
577 uint16_t addr;
578 } va_subs[] = {
579 { .uuid = TEST_VA_0_UUID, .addr = TEST_VA_0_ADDR, },
580 { .uuid = TEST_VA_1_UUID, .addr = TEST_VA_1_ADDR, },
581 { .uuid = TEST_VA_1_UUID_COL, .addr = TEST_VA_1_ADDR, },
582 };
583
584 for (size_t i = 0; i < ARRAY_SIZE(va_subs); i++) {
585 err = bt_mesh_cfg_cli_mod_sub_va_add(test_netkey_idx, TEST_ADDR, TEST_ADDR,
586 va_subs[i].uuid, TEST_MOD_ID, &va, &status);
587 if (err || status) {
588 FAIL("Mod sub add failed (err %d, status %u)", err, status);
589 }
590 ASSERT_EQUAL(va_subs[i].addr, va);
591 }
592
593 memcpy(&pub_params, &(struct bt_mesh_cfg_cli_mod_pub)TEST_MOD_PUB_PARAMS,
594 sizeof(struct bt_mesh_cfg_cli_mod_pub));
595 err = bt_mesh_cfg_cli_mod_pub_set(test_netkey_idx, TEST_ADDR, TEST_ADDR, TEST_MOD_ID,
596 &pub_params, &status);
597 if (err || status) {
598 FAIL("Mod pub set failed (err %d, status %u)", err, status);
599 }
600
601 err = bt_mesh_model_data_store(test_model, false, TEST_MOD_DATA_NAME, test_mod_data,
602 sizeof(test_mod_data));
603 if (err) {
604 FAIL("Mod data store failed (err %d)", err);
605 }
606
607 /* Vendor model. */
608 for (size_t i = 0; i < ARRAY_SIZE(test_appkeys); i++) {
609 err = bt_mesh_cfg_cli_mod_app_bind_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR,
610 test_appkeys[i].idx, TEST_VND_MOD_ID,
611 TEST_VND_COMPANY_ID, &status);
612 if (err || status) {
613 FAIL("Mod app bind failed (err %d, status %u, i %d)", err, status, i);
614 }
615 }
616
617 err = bt_mesh_cfg_cli_mod_sub_add_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR,
618 TEST_GROUP_0, TEST_VND_MOD_ID,
619 TEST_VND_COMPANY_ID, &status);
620 if (err || status) {
621 FAIL("Mod sub add failed (err %d, status %u)", err, status);
622 }
623
624 for (size_t i = 0; i < ARRAY_SIZE(va_subs); i++) {
625 err = bt_mesh_cfg_cli_mod_sub_va_add_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR,
626 va_subs[i].uuid, TEST_VND_MOD_ID,
627 TEST_VND_COMPANY_ID, &va, &status);
628 if (err || status) {
629 FAIL("Mod sub add failed (err %d, status %u)", err, status);
630 }
631 ASSERT_EQUAL(va_subs[i].addr, va);
632 }
633
634 memcpy(&pub_params, &(struct bt_mesh_cfg_cli_mod_pub)TEST_VND_MOD_PUB_PARAMS,
635 sizeof(struct bt_mesh_cfg_cli_mod_pub));
636 err = bt_mesh_cfg_cli_mod_pub_set_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR,
637 TEST_VND_MOD_ID, TEST_VND_COMPANY_ID, &pub_params,
638 &status);
639 if (err || status) {
640 FAIL("Mod pub set failed (err %d, status %u)", err, status);
641 }
642
643 err = bt_mesh_model_data_store(test_vnd_model, true, TEST_VND_MOD_DATA_NAME,
644 vnd_test_mod_data, sizeof(vnd_test_mod_data));
645 if (err) {
646 FAIL("Vnd mod data store failed (err %d)", err);
647 return;
648 }
649 }
650
test_access_data_save(void)651 static void test_access_data_save(void)
652 {
653 bt_mesh_test_cfg_set(NULL, WAIT_TIME);
654
655 if (device_setup_and_self_provision()) {
656 FAIL("Mesh setup failed. Settings should not be loaded.");
657 }
658
659 node_configure();
660
661 k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT));
662
663 PASS();
664 }
665
node_configuration_check(const struct access_cfg (* cfg)[2])666 static void node_configuration_check(const struct access_cfg (*cfg)[2])
667 {
668 uint16_t appkeys[CONFIG_BT_MESH_MODEL_KEY_COUNT + 1];
669 size_t appkeys_count = ARRAY_SIZE(appkeys);
670 uint16_t subs[CONFIG_BT_MESH_MODEL_GROUP_COUNT + 1];
671 size_t subs_count = ARRAY_SIZE(subs);
672 uint8_t status;
673 int err;
674
675 for (size_t m = 0; m < 2; m++) {
676 bool vnd = m == 1;
677
678 if (!vnd) {
679 err = bt_mesh_cfg_cli_mod_app_get(test_netkey_idx, TEST_ADDR, TEST_ADDR,
680 TEST_MOD_ID, &status, appkeys,
681 &appkeys_count);
682 } else {
683 err = bt_mesh_cfg_cli_mod_app_get_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR,
684 TEST_VND_MOD_ID, TEST_VND_COMPANY_ID,
685 &status, appkeys, &appkeys_count);
686 }
687 if (err || status) {
688 FAIL("Mod app get failed (err %d, status %u)", err, status);
689 }
690
691 ASSERT_EQUAL((*cfg)[m].appkeys_count, appkeys_count);
692 for (size_t i = 0; i < appkeys_count; i++) {
693 ASSERT_EQUAL((*cfg)[m].appkeys[i], appkeys[i]);
694 }
695
696 if (!vnd) {
697 err = bt_mesh_cfg_cli_mod_sub_get(test_netkey_idx, TEST_ADDR, TEST_ADDR,
698 TEST_MOD_ID, &status, subs, &subs_count);
699 } else {
700 err = bt_mesh_cfg_cli_mod_sub_get_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR,
701 TEST_VND_MOD_ID, TEST_VND_COMPANY_ID,
702 &status, subs, &subs_count);
703 }
704 if (err || status) {
705 FAIL("Mod sub get failed (err %d, status %u)", err, status);
706 }
707
708 ASSERT_EQUAL((*cfg)[m].subs_count, subs_count);
709 for (size_t i = 0; i < subs_count; i++) {
710 ASSERT_EQUAL((*cfg)[m].subs[i], subs[i]);
711 }
712
713 struct bt_mesh_cfg_cli_mod_pub pub_params = {};
714
715 if (!vnd) {
716 err = bt_mesh_cfg_cli_mod_pub_get(test_netkey_idx, TEST_ADDR, TEST_ADDR,
717 TEST_MOD_ID, &pub_params, &status);
718 } else {
719 err = bt_mesh_cfg_cli_mod_pub_get_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR,
720 TEST_VND_MOD_ID, TEST_VND_COMPANY_ID,
721 &pub_params, &status);
722 }
723 if (err || status) {
724 FAIL("Mod pub get failed (err %d, status %u)", err, status);
725 }
726
727 check_mod_pub_params(&(*cfg)[m].pub_params, &pub_params);
728 }
729 }
730
test_access_data_load(void)731 static void test_access_data_load(void)
732 {
733 ASSERT_TRUE(current_access_cfg != NULL);
734
735 /* In this test stack should boot as provisioned */
736 bt_mesh_test_cfg_set(NULL, WAIT_TIME);
737
738 if (device_setup_and_self_provision() != -EALREADY) {
739 FAIL("Device should boot up as already provisioned");
740 }
741
742 node_configuration_check(current_access_cfg);
743
744 PASS();
745 }
746
test_access_sub_overwrite(void)747 static void test_access_sub_overwrite(void)
748 {
749 struct bt_mesh_cfg_cli_mod_pub pub_params;
750 uint16_t va;
751 uint8_t status;
752 int err;
753
754 /* In this test stack should boot as provisioned */
755 bt_mesh_test_cfg_set(NULL, WAIT_TIME);
756
757 if (device_setup_and_self_provision() != -EALREADY) {
758 FAIL("Device should boot up as already provisioned");
759 }
760
761 err = bt_mesh_cfg_cli_mod_sub_overwrite(test_netkey_idx, TEST_ADDR, TEST_ADDR,
762 TEST_GROUP_0, TEST_MOD_ID, &status);
763 if (err || status) {
764 FAIL("Mod sub overwrite failed (err %d, status %u)", err, status);
765 }
766
767 memcpy(&pub_params, &(struct bt_mesh_cfg_cli_mod_pub)TEST_MOD_PUB_PARAMS_2,
768 sizeof(struct bt_mesh_cfg_cli_mod_pub));
769 err = bt_mesh_cfg_cli_mod_pub_set(test_netkey_idx, TEST_ADDR, TEST_ADDR, TEST_MOD_ID,
770 &pub_params, &status);
771 if (err || status) {
772 FAIL("Mod pub set failed (err %d, status %u)", err, status);
773 }
774
775 /* Vendor model. */
776 err = bt_mesh_cfg_cli_mod_sub_va_overwrite_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR,
777 TEST_VA_0_UUID, TEST_VND_MOD_ID,
778 TEST_VND_COMPANY_ID, &va, &status);
779 if (err || status) {
780 FAIL("Mod sub va overwrite failed (err %d, status %u)", err, status);
781 }
782 ASSERT_EQUAL(TEST_VA_0_ADDR, va);
783
784 memcpy(&pub_params, &(struct bt_mesh_cfg_cli_mod_pub)TEST_VND_MOD_PUB_PARAMS_2,
785 sizeof(struct bt_mesh_cfg_cli_mod_pub));
786 err = bt_mesh_cfg_cli_mod_pub_set_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR,
787 TEST_VND_MOD_ID, TEST_VND_COMPANY_ID, &pub_params,
788 &status);
789 if (err || status) {
790 FAIL("Mod pub set failed (err %d, status %u)", err, status);
791 }
792
793 k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT));
794
795 PASS();
796 }
797
test_access_data_remove(void)798 static void test_access_data_remove(void)
799 {
800 int err;
801 uint8_t status;
802 struct bt_mesh_cfg_cli_mod_pub pub_params;
803
804 /* In this test stack should boot as provisioned */
805 bt_mesh_test_cfg_set(NULL, WAIT_TIME);
806
807 if (device_setup_and_self_provision() != -EALREADY) {
808 FAIL("Device should boot up as already provisioned");
809 }
810
811 struct test_appkey_t test_appkeys[] = {
812 { .idx = TEST_APPKEY_0_IDX, .key = TEST_APPKEY_0_KEY },
813 { .idx = TEST_APPKEY_1_IDX, .key = TEST_APPKEY_1_KEY },
814 };
815
816 /* SIG Model. */
817 for (size_t i = 0; i < ARRAY_SIZE(test_appkeys); i++) {
818 err = bt_mesh_cfg_cli_mod_app_unbind(test_netkey_idx, TEST_ADDR, TEST_ADDR,
819 test_appkeys[i].idx, TEST_MOD_ID, &status);
820 if (err || status) {
821 FAIL("Mod app bind failed (err %d, status %u, i %d)", err, status, i);
822 }
823 }
824
825 err = bt_mesh_cfg_cli_mod_sub_del_all(test_netkey_idx, TEST_ADDR, TEST_ADDR, TEST_MOD_ID,
826 &status);
827 if (err || status) {
828 FAIL("Mod sub del all failed (err %d, status %u)", err, status);
829 }
830
831 memcpy(&pub_params, &(struct bt_mesh_cfg_cli_mod_pub)TEST_MOD_PUB_PARAMS,
832 sizeof(struct bt_mesh_cfg_cli_mod_pub));
833 pub_params.addr = BT_MESH_ADDR_UNASSIGNED;
834 err = bt_mesh_cfg_cli_mod_pub_set(test_netkey_idx, TEST_ADDR, TEST_ADDR, TEST_MOD_ID,
835 &pub_params, &status);
836 if (err || status) {
837 FAIL("Mod pub set failed (err %d, status %u)", err, status);
838 }
839
840 err = bt_mesh_model_data_store(test_model, false, TEST_MOD_DATA_NAME, NULL, 0);
841 if (err) {
842 FAIL("Mod data erase failed (err %d)", err);
843 }
844
845 /* Vendor model. */
846 for (size_t i = 0; i < ARRAY_SIZE(test_appkeys); i++) {
847 err = bt_mesh_cfg_cli_mod_app_unbind_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR,
848 test_appkeys[i].idx, TEST_VND_MOD_ID,
849 TEST_VND_COMPANY_ID, &status);
850 if (err || status) {
851 FAIL("Mod app bind failed (err %d, status %u, i %d)", err, status, i);
852 }
853 }
854
855 err = bt_mesh_cfg_cli_mod_sub_del_all_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR,
856 TEST_VND_MOD_ID, TEST_VND_COMPANY_ID,
857 &status);
858 if (err || status) {
859 FAIL("Mod sub del all failed (err %d, status %u)", err, status);
860 }
861
862 memcpy(&pub_params, &(struct bt_mesh_cfg_cli_mod_pub)TEST_VND_MOD_PUB_PARAMS,
863 sizeof(struct bt_mesh_cfg_cli_mod_pub));
864 pub_params.addr = BT_MESH_ADDR_UNASSIGNED;
865 pub_params.uuid = NULL;
866 err = bt_mesh_cfg_cli_mod_pub_set_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR,
867 TEST_VND_MOD_ID, TEST_VND_COMPANY_ID, &pub_params,
868 &status);
869 if (err || status) {
870 FAIL("Mod pub set failed (err %d, status %u)", err, status);
871 }
872
873 err = bt_mesh_model_data_store(test_vnd_model, true, TEST_VND_MOD_DATA_NAME, NULL, 0);
874 if (err) {
875 FAIL("Vnd mod data erase failed (err %d)", err);
876 return;
877 }
878
879 k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT));
880
881 PASS();
882 }
883
test_cfg_save(void)884 static void test_cfg_save(void)
885 {
886 uint8_t transmit;
887 uint8_t status;
888 int err;
889
890 ASSERT_TRUE(current_stack_cfg != NULL);
891
892 bt_mesh_test_cfg_set(NULL, WAIT_TIME);
893
894 if (device_setup_and_self_provision()) {
895 FAIL("Mesh setup failed. Settings should not be loaded.");
896 }
897
898 err = bt_mesh_cfg_cli_beacon_set(test_netkey_idx, TEST_ADDR,
899 current_stack_cfg->beacon, &status);
900 if (err || status != current_stack_cfg->beacon) {
901 FAIL("Beacon set failed (err %d, status %u)", err, status);
902 }
903
904 err = bt_mesh_cfg_cli_ttl_set(test_netkey_idx, TEST_ADDR,
905 current_stack_cfg->ttl, &status);
906 if (err || status != current_stack_cfg->ttl) {
907 FAIL("TTL set failed (err %d, status %u)", err, status);
908 }
909
910 err = bt_mesh_cfg_cli_gatt_proxy_set(test_netkey_idx, TEST_ADDR,
911 current_stack_cfg->gatt_proxy, &status);
912 if (err || status != current_stack_cfg->gatt_proxy) {
913 FAIL("GATT Proxy set failed (err %d, status %u)", err, status);
914 }
915
916 err = bt_mesh_cfg_cli_friend_set(test_netkey_idx, TEST_ADDR,
917 current_stack_cfg->friend, &status);
918 if (err || status != current_stack_cfg->friend) {
919 FAIL("Friend set failed (err %d, status %u)", err, status);
920 }
921
922 err = bt_mesh_cfg_cli_net_transmit_set(test_netkey_idx, TEST_ADDR,
923 current_stack_cfg->net_transmit,
924 &transmit);
925 if (err || transmit != current_stack_cfg->net_transmit) {
926 FAIL("Net transmit set failed (err %d, transmit %x)", err, transmit);
927 }
928
929 err = bt_mesh_cfg_cli_relay_set(test_netkey_idx, TEST_ADDR,
930 current_stack_cfg->relay.state,
931 current_stack_cfg->relay.transmit,
932 &status, &transmit);
933 if (err || status != current_stack_cfg->relay.state ||
934 transmit != current_stack_cfg->relay.transmit) {
935 FAIL("Relay set failed (err %d, status %u, transmit %x)", err, status,
936 current_stack_cfg->relay.transmit);
937 }
938
939 #ifdef CONFIG_BT_MESH_PRIV_BEACONS
940 struct bt_mesh_priv_beacon priv_beacon_state = {
941 .enabled = current_stack_cfg->priv_beacon,
942 .rand_interval = current_stack_cfg->priv_beacon_int,
943 };
944
945 err = bt_mesh_priv_beacon_cli_set(test_netkey_idx, TEST_ADDR, &priv_beacon_state);
946 if (err) {
947 FAIL("Failed to enable Private Beacon (err %d)", err);
948 }
949
950 uint8_t priv_beacon_gatt = current_stack_cfg->priv_beacon_gatt;
951
952 err = bt_mesh_priv_beacon_cli_gatt_proxy_set(test_netkey_idx, TEST_ADDR, &priv_beacon_gatt);
953 if (err) {
954 FAIL("Failed to enable Private Beacon GATT proxy (err %d)", err);
955 }
956 #endif
957
958 #if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) && defined(CONFIG_BT_MESH_OD_PRIV_PROXY_CLI)
959 uint8_t priv_proxy_val;
960
961 err = bt_mesh_od_priv_proxy_cli_set(test_netkey_idx, TEST_ADDR,
962 current_stack_cfg->priv_proxy_val, &priv_proxy_val);
963 if (err || priv_proxy_val != current_stack_cfg->priv_proxy_val) {
964 FAIL("Failed to set OD Private proxy (err %d, value %d)", err, priv_proxy_val);
965 }
966 #endif
967
968 k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT));
969
970 PASS();
971 }
972
test_cfg_load(void)973 static void test_cfg_load(void)
974 {
975 uint8_t transmit;
976 uint8_t status;
977 int err;
978
979 ASSERT_TRUE(current_stack_cfg != NULL);
980
981 /* In this test stack should boot as provisioned */
982 bt_mesh_test_cfg_set(NULL, WAIT_TIME);
983
984 if (device_setup_and_self_provision() != -EALREADY) {
985 FAIL("Device should boot up as already provisioned");
986 }
987
988 err = bt_mesh_cfg_cli_beacon_get(test_netkey_idx, TEST_ADDR, &status);
989 if (err || status != current_stack_cfg->beacon) {
990 FAIL("Beacon get failed (err %d, status %u)", err, status);
991 }
992
993 err = bt_mesh_cfg_cli_ttl_get(test_netkey_idx, TEST_ADDR, &status);
994 if (err || status != current_stack_cfg->ttl) {
995 FAIL("TTL get failed (err %d, status %u)", err, status);
996 }
997
998 err = bt_mesh_cfg_cli_gatt_proxy_get(test_netkey_idx, TEST_ADDR, &status);
999 if (err || status != current_stack_cfg->gatt_proxy) {
1000 FAIL("GATT Proxy get failed (err %d, status %u)", err, status);
1001 }
1002
1003 err = bt_mesh_cfg_cli_friend_get(test_netkey_idx, TEST_ADDR, &status);
1004 if (err || status != current_stack_cfg->friend) {
1005 FAIL("Friend get failed (err %d, status %u)", err, status);
1006 }
1007
1008 err = bt_mesh_cfg_cli_net_transmit_get(test_netkey_idx, TEST_ADDR, &status);
1009 if (err || status != current_stack_cfg->net_transmit) {
1010 FAIL("Net transmit get failed (err %d, status %u)", err, status);
1011 }
1012
1013 err = bt_mesh_cfg_cli_relay_get(test_netkey_idx, TEST_ADDR, &status, &transmit);
1014 if (err || status != current_stack_cfg->relay.state ||
1015 transmit != current_stack_cfg->relay.transmit) {
1016 FAIL("Relay get failed (err %d, state %u, transmit %x)", err, status, transmit);
1017 }
1018
1019 #ifdef CONFIG_BT_MESH_PRIV_BEACONS
1020 struct bt_mesh_priv_beacon priv_beacon_state;
1021 uint8_t priv_beacon_gatt;
1022
1023 err = bt_mesh_priv_beacon_cli_get(test_netkey_idx, TEST_ADDR, &priv_beacon_state);
1024 if (err || priv_beacon_state.enabled != current_stack_cfg->priv_beacon ||
1025 priv_beacon_state.rand_interval != current_stack_cfg->priv_beacon_int) {
1026 FAIL("Private beacon get failed (err %d, enabled %u, interval %x)", err,
1027 priv_beacon_state.enabled, priv_beacon_state.rand_interval);
1028 }
1029
1030 err = bt_mesh_priv_beacon_cli_gatt_proxy_get(test_netkey_idx, TEST_ADDR, &priv_beacon_gatt);
1031 if (err || priv_beacon_gatt != current_stack_cfg->priv_beacon_gatt) {
1032 FAIL("Private beacon GATT proxy get failed (err %d, enabled %u)", err,
1033 priv_beacon_gatt);
1034 }
1035 #endif
1036
1037 #if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) && defined(CONFIG_BT_MESH_OD_PRIV_PROXY_CLI)
1038 uint8_t priv_proxy_val;
1039
1040 err = bt_mesh_od_priv_proxy_cli_get(test_netkey_idx, TEST_ADDR, &priv_proxy_val);
1041 if (err || priv_proxy_val != current_stack_cfg->priv_proxy_val) {
1042 FAIL("Private proxy get failed (err %d, value %u)", err, priv_proxy_val);
1043 }
1044 #endif
1045
1046 PASS();
1047 }
1048
mesh_settings_load_cb(const char * key,size_t len,settings_read_cb read_cb,void * cb_arg,void * param)1049 static int mesh_settings_load_cb(const char *key, size_t len, settings_read_cb read_cb,
1050 void *cb_arg, void *param)
1051 {
1052 ASSERT_TRUE(len == 0);
1053
1054 return 0;
1055 }
1056
1057 /** @brief Test reprovisioning with persistent storage, device side.
1058 *
1059 * Wait for being provisioned and configured, then wait for the node reset and store settings.
1060 */
test_reprovisioning_device(void)1061 static void test_reprovisioning_device(void)
1062 {
1063 bt_mesh_test_cfg_set(NULL, WAIT_TIME);
1064
1065 device_setup();
1066
1067 ASSERT_FALSE(bt_mesh_is_provisioned());
1068
1069 ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_ADV));
1070
1071 LOG_INF("Waiting for being provisioned...");
1072 ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40)));
1073
1074 LOG_INF("Waiting for the node reset...");
1075 ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40)));
1076
1077 k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT));
1078
1079 /* Check that all mesh settings were removed. */
1080 settings_load_subtree_direct("bt/mesh", mesh_settings_load_cb, NULL);
1081
1082 PASS();
1083 }
1084
1085 /** @brief Test reprovisioning with persistent storage, provisioner side.
1086 *
1087 * Verify that a device can clear its data from persistent storage after node reset.
1088 */
test_reprovisioning_provisioner(void)1089 static void test_reprovisioning_provisioner(void)
1090 {
1091 int err;
1092 bool status;
1093
1094 bt_mesh_test_cfg_set(NULL, WAIT_TIME);
1095
1096 provisioner_setup();
1097
1098 LOG_INF("Provisioning a remote device...");
1099 ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40)));
1100
1101 /* Verify that the remote device is not configured. */
1102 node_configuration_check(&access_cfgs[NOT_CONFIGURED]);
1103
1104 /* Configure the remote device. */
1105 node_configure();
1106
1107 /* Let the remote device store configuration. */
1108 k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT * 2));
1109
1110 err = bt_mesh_cfg_cli_node_reset(test_netkey_idx, TEST_ADDR, &status);
1111 if (err || !status) {
1112 FAIL("Reset failed (err %d, status: %d)", err, status);
1113 }
1114
1115 /* Let the remote device store configuration. */
1116 k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT * 2));
1117
1118 PASS();
1119 }
1120
1121 #define TEST_CASE(role, name, description) \
1122 { \
1123 .test_id = "persistence_" #role "_" #name, \
1124 .test_args_f = test_args_parse, \
1125 .test_descr = description, \
1126 .test_tick_f = bt_mesh_test_timeout, \
1127 .test_main_f = test_##role##_##name, \
1128 }
1129
1130 static const struct bst_test_instance test_persistence[] = {
1131 TEST_CASE(provisioning, data_save, "Save provisioning data"),
1132 TEST_CASE(provisioning, data_load, "Load previously saved data and verify"),
1133 TEST_CASE(access, data_save, "Save access data"),
1134 TEST_CASE(access, data_load, "Load previously saved access data and verify"),
1135 TEST_CASE(access, sub_overwrite, "Overwrite Subscription List and store"),
1136 TEST_CASE(access, data_remove, "Remove stored access data"),
1137 TEST_CASE(cfg, save, "Save mesh configuration"),
1138 TEST_CASE(cfg, load, "Load previously stored mesh configuration and verify"),
1139 TEST_CASE(reprovisioning, device, "Reprovisioning test, device role"),
1140 TEST_CASE(reprovisioning, provisioner, "Reprovisioning test, provisioner role"),
1141 BSTEST_END_MARKER
1142 };
1143
test_persistence_install(struct bst_test_list * tests)1144 struct bst_test_list *test_persistence_install(struct bst_test_list *tests)
1145 {
1146 return bst_add_tests(tests, test_persistence);
1147 }
1148