1 /*
2  * Copyright (c) 2017 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /* Tree walk return codes */
8 enum bt_mesh_walk {
9 	BT_MESH_WALK_STOP,
10 	BT_MESH_WALK_CONTINUE,
11 };
12 
13 /* bt_mesh_model.flags */
14 enum {
15 	BT_MESH_MOD_BIND_PENDING = BIT(0),
16 	BT_MESH_MOD_SUB_PENDING = BIT(1),
17 	BT_MESH_MOD_PUB_PENDING = BIT(2),
18 	BT_MESH_MOD_EXTENDED = BIT(3),
19 	BT_MESH_MOD_DEVKEY_ONLY = BIT(4),
20 	BT_MESH_MOD_DATA_PENDING = BIT(5),
21 };
22 
23 void bt_mesh_elem_register(const struct bt_mesh_elem *elem, uint8_t count);
24 
25 uint8_t bt_mesh_elem_count(void);
26 size_t bt_mesh_comp_page_size(uint8_t page);
27 int bt_mesh_comp_data_get_page_0(struct net_buf_simple *buf, size_t offset);
28 size_t bt_mesh_metadata_page_0_size(void);
29 int bt_mesh_metadata_get_page_0(struct net_buf_simple *buf, size_t offset);
30 
31 /* Find local element based on unicast address */
32 const struct bt_mesh_elem *bt_mesh_elem_find(uint16_t addr);
33 
34 bool bt_mesh_has_addr(uint16_t addr);
35 bool bt_mesh_model_has_key(const struct bt_mesh_model *mod, uint16_t key);
36 
37 void bt_mesh_model_extensions_walk(const struct bt_mesh_model *root,
38 				   enum bt_mesh_walk (*cb)(const struct bt_mesh_model *mod,
39 							   void *user_data),
40 				   void *user_data);
41 
42 uint16_t *bt_mesh_model_find_group(const struct bt_mesh_model **mod, uint16_t addr);
43 const uint8_t **bt_mesh_model_find_uuid(const struct bt_mesh_model **mod, const uint8_t *uuid);
44 
45 void bt_mesh_model_foreach(void (*func)(const struct bt_mesh_model *mod,
46 					const struct bt_mesh_elem *elem,
47 					bool vnd, bool primary,
48 					void *user_data),
49 			   void *user_data);
50 
51 int32_t bt_mesh_model_pub_period_get(const struct bt_mesh_model *mod);
52 
53 void bt_mesh_comp_provision(uint16_t addr);
54 void bt_mesh_comp_unprovision(void);
55 
56 uint16_t bt_mesh_primary_addr(void);
57 
58 const struct bt_mesh_comp *bt_mesh_comp_get(void);
59 
60 const struct bt_mesh_model *bt_mesh_model_get(bool vnd, uint8_t elem_idx, uint8_t mod_idx);
61 
62 int bt_mesh_access_recv(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
63 int bt_mesh_model_recv(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
64 
65 int bt_mesh_comp_register(const struct bt_mesh_comp *comp);
66 int bt_mesh_comp_store(void);
67 int bt_mesh_comp_read(struct net_buf_simple *buf, uint8_t page);
68 uint8_t bt_mesh_comp_parse_page(struct net_buf_simple *buf);
69 
70 int bt_mesh_models_metadata_store(void);
71 int bt_mesh_models_metadata_read(struct net_buf_simple *buf, size_t offset);
72 
73 void bt_mesh_comp_data_pending_clear(void);
74 void bt_mesh_comp_data_clear(void);
75 int bt_mesh_comp_data_get_page(struct net_buf_simple *buf, size_t page, size_t offset);
76 
77 void bt_mesh_model_pending_store(void);
78 void bt_mesh_model_bind_store(const struct bt_mesh_model *mod);
79 void bt_mesh_model_sub_store(const struct bt_mesh_model *mod);
80 void bt_mesh_model_pub_store(const struct bt_mesh_model *mod);
81 void bt_mesh_model_settings_commit(void);
82 
83 /** @brief Register a callback function hook for mesh model messages.
84  *
85  * Register a callback function to act as a hook for receiving mesh model layer messages
86  * directly to the application without having instantiated the relevant models.
87  *
88  * @param cb A pointer to the callback function.
89  */
90 void bt_mesh_msg_cb_set(void (*cb)(uint32_t opcode, struct bt_mesh_msg_ctx *ctx,
91 			struct net_buf_simple *buf));
92 
93 /** @brief Send a mesh model message.
94  *
95  * Send a mesh model layer message out into the mesh network without having instantiated
96  * the relevant mesh models.
97  *
98  * @param ctx The Bluetooth Mesh message context.
99  * @param buf The message payload.
100  * @param src_addr The source address of model
101  * @param cb Callback function.
102  * @param cb_data Callback data.
103  *
104  * @return 0 on success or negative error code on failure.
105  */
106 int bt_mesh_access_send(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf, uint16_t src_addr,
107 			const struct bt_mesh_send_cb *cb, void *cb_data);
108 
109 /** @brief Initialize the Access layer.
110  *
111  * Initialize the delayable message mechanism if it has been enabled.
112  */
113 void bt_mesh_access_init(void);
114 
115 /** @brief Suspend the Access layer.
116  */
117 void bt_mesh_access_suspend(void);
118 
119 /** @brief Reset the Access layer.
120  */
121 void bt_mesh_access_reset(void);
122