1 /**
2  * @file testing.h
3  * @brief Internal API for Bluetooth testing.
4  */
5 
6 /*
7  * Copyright (c) 2017 Intel Corporation
8  * Copyright (c) 2024 Nordic Semiconductor ASA
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  */
12 
13 #include <stdint.h>
14 
15 #include <zephyr/bluetooth/mesh.h>
16 #include <zephyr/bluetooth/mesh/access.h>
17 #include <zephyr/sys/slist.h>
18 
19 /** @brief Bluetooth Testing callbacks structure.
20  *
21  *  Callback structure to be used for Bluetooth testing purposes.
22  *  Allows access to Bluetooth stack internals, not exposed by public API.
23  */
24 struct bt_mesh_test_cb {
25 	void (*net_recv)(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const void *payload,
26 			 size_t payload_len);
27 	void (*model_recv)(uint16_t src, uint16_t dst, const void *payload, size_t payload_len);
28 	void (*model_bound)(uint16_t addr, const struct bt_mesh_model *model, uint16_t key_idx);
29 	void (*model_unbound)(uint16_t addr, const struct bt_mesh_model *model, uint16_t key_idx);
30 	void (*prov_invalid_bearer)(uint8_t opcode);
31 	void (*trans_incomp_timer_exp)(void);
32 
33 	sys_snode_t node;
34 };
35 
36 /** Register callbacks for Bluetooth testing purposes
37  *
38  *  @param cb bt_mesh_test_cb callback structure
39  *
40  * @retval 0 Success.
41  * @retval -EEXIST if @p cb was already registered.
42  */
43 int bt_mesh_test_cb_register(struct bt_mesh_test_cb *cb);
44 
45 /** Unregister callbacks for Bluetooth testing purposes
46  *
47  *  @param cb bt_mesh_test_cb callback structure
48  */
49 void bt_mesh_test_cb_unregister(struct bt_mesh_test_cb *cb);
50 
51 /** Send Friend Subscription List Add message.
52  *
53  *  Used by Low Power node to send the group address for which messages are to
54  *  be stored by Friend node.
55  *
56  *  @param group Group address
57  *
58  *  @return Zero on success or (negative) error code otherwise.
59  */
60 int bt_mesh_test_lpn_group_add(uint16_t group);
61 
62 /** Send Friend Subscription List Remove message.
63  *
64  *  Used by Low Power node to remove the group addresses from Friend node
65  *  subscription list. Messages sent to those addresses will not be stored
66  *  by Friend node.
67  *
68  *  @param groups Group addresses
69  *  @param groups_count Group addresses count
70  *
71  *  @return Zero on success or (negative) error code otherwise.
72  */
73 int bt_mesh_test_lpn_group_remove(uint16_t *groups, size_t groups_count);
74 
75 /** Clear replay protection list cache.
76  *
77  *  @return Zero on success or (negative) error code otherwise.
78  */
79 int bt_mesh_test_rpl_clear(void);
80 
81 void bt_mesh_test_net_recv(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst,
82 			   const void *payload, size_t payload_len);
83 void bt_mesh_test_model_recv(uint16_t src, uint16_t dst, const void *payload, size_t payload_len);
84 void bt_mesh_test_model_bound(uint16_t addr, const struct bt_mesh_model *model, uint16_t key_idx);
85 void bt_mesh_test_model_unbound(uint16_t addr, const struct bt_mesh_model *model, uint16_t key_idx);
86 void bt_mesh_test_prov_invalid_bearer(uint8_t opcode);
87 void bt_mesh_test_trans_incomp_timer_exp(void);
88