1 /*
2 * Copyright (c) 2017 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <ble_os.h>
8 #include <stddef.h>
9
10 #include <bluetooth/mesh.h>
11 #include <bluetooth/testing.h>
12
13 #if defined(CONFIG_BT_MESH)
14 #include "mesh/net.h"
15 #include "mesh/lpn.h"
16 #include "mesh/transport.h"
17 #endif /* CONFIG_BT_MESH */
18
19 #include "testing.h"
20
21 static sys_slist_t cb_slist;
22
bt_test_cb_register(struct bt_test_cb * cb)23 void bt_test_cb_register(struct bt_test_cb *cb)
24 {
25 sys_slist_append(&cb_slist, &cb->node);
26 }
27
bt_test_cb_unregister(struct bt_test_cb * cb)28 void bt_test_cb_unregister(struct bt_test_cb *cb)
29 {
30 sys_slist_find_and_remove(&cb_slist, &cb->node);
31 }
32
33 #if defined(CONFIG_BT_MESH)
bt_test_mesh_net_recv(u8_t ttl,u8_t ctl,u16_t src,u16_t dst,const void * payload,size_t payload_len)34 void bt_test_mesh_net_recv(u8_t ttl, u8_t ctl, u16_t src, u16_t dst,
35 const void *payload, size_t payload_len)
36 {
37 struct bt_test_cb *cb;
38
39 SYS_SLIST_FOR_EACH_CONTAINER(&cb_slist, cb, node) {
40 if (cb->mesh_net_recv) {
41 cb->mesh_net_recv(ttl, ctl, src, dst, payload,
42 payload_len);
43 }
44 }
45 }
46
bt_test_mesh_model_bound(u16_t addr,struct bt_mesh_model * model,u16_t key_idx)47 void bt_test_mesh_model_bound(u16_t addr, struct bt_mesh_model *model,
48 u16_t key_idx)
49 {
50 struct bt_test_cb *cb;
51
52 SYS_SLIST_FOR_EACH_CONTAINER(&cb_slist, cb, node) {
53 if (cb->mesh_model_bound) {
54 cb->mesh_model_bound(addr, model, key_idx);
55 }
56 }
57 }
58
bt_test_mesh_model_unbound(u16_t addr,struct bt_mesh_model * model,u16_t key_idx)59 void bt_test_mesh_model_unbound(u16_t addr, struct bt_mesh_model *model,
60 u16_t key_idx)
61 {
62 struct bt_test_cb *cb;
63
64 SYS_SLIST_FOR_EACH_CONTAINER(&cb_slist, cb, node) {
65 if (cb->mesh_model_unbound) {
66 cb->mesh_model_unbound(addr, model, key_idx);
67 }
68 }
69 }
70
bt_test_mesh_prov_invalid_bearer(u8_t opcode)71 void bt_test_mesh_prov_invalid_bearer(u8_t opcode)
72 {
73 struct bt_test_cb *cb;
74
75 SYS_SLIST_FOR_EACH_CONTAINER(&cb_slist, cb, node) {
76 if (cb->mesh_prov_invalid_bearer) {
77 cb->mesh_prov_invalid_bearer(opcode);
78 }
79 }
80 }
81
bt_test_mesh_trans_incomp_timer_exp(void)82 void bt_test_mesh_trans_incomp_timer_exp(void)
83 {
84 struct bt_test_cb *cb;
85
86 SYS_SLIST_FOR_EACH_CONTAINER(&cb_slist, cb, node) {
87 if (cb->mesh_trans_incomp_timer_exp) {
88 cb->mesh_trans_incomp_timer_exp();
89 }
90 }
91 }
92
bt_test_mesh_lpn_group_add(u16_t group)93 int bt_test_mesh_lpn_group_add(u16_t group)
94 {
95 bt_mesh_lpn_group_add(group);
96
97 return 0;
98 }
99
bt_test_mesh_lpn_group_remove(u16_t * groups,size_t groups_count)100 int bt_test_mesh_lpn_group_remove(u16_t *groups, size_t groups_count)
101 {
102 bt_mesh_lpn_group_del(groups, groups_count);
103
104 return 0;
105 }
106
bt_test_mesh_rpl_clear(void)107 int bt_test_mesh_rpl_clear(void)
108 {
109 bt_mesh_rpl_clear();
110
111 return 0;
112 }
113 #endif /* CONFIG_BT_MESH */
114