MeshX 0.4
This repository provides an implementation for Bluetooth Low Energy (BLE) Mesh network nodes. The project allows you to create BLE mesh nodes that can communicate with each other, enabling the development of smart home solutions or other IoT-based applications.
Loading...
Searching...
No Matches
meshx_ble_mesh_cmn.h
Go to the documentation of this file.
1/**
2 * Copyright (c) 2024 - 2025 MeshX
3 *
4 * @file meshx_ble_mesh_cmn.h
5 * @brief Common BLE Mesh interface definitions and utility functions.
6 *
7 * This header file contains the definitions and function declarations for
8 * managing BLE Mesh models, contexts, and compositions. It provides utilities
9 * for checking model subscriptions, creating and deleting model structures,
10 * retrieving model IDs, and managing BLE Mesh compositions.
11 *
12 * The functions defined here facilitate the initialization, manipulation, and
13 * cleanup of BLE Mesh components, ensuring efficient memory management and
14 * error handling.
15 *
16 * @author Pranjal Chanda
17 */
18#ifndef __MESHX_PLAT_SRV_CMN_H__
19#define __MESHX_PLAT_SRV_CMN_H__
20
21#include "stdlib.h"
22#include "string.h"
23#include "meshx_err.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/*
32 * @brief Structure to hold UUID and address information.
33 */
34typedef struct meshx_model
35{
36 uint16_t el_id; /**< Element ID */
37 uint16_t model_id; /**< Model ID */
38 uint16_t pub_addr; /**< Publication address. Used by client models */
39 meshx_ptr_t p_model; /**< Pointer to the model structure */
41
42/**
43 * @brief Structure to hold context information for BLE Mesh operations.
44 */
45typedef struct meshx_ctx
46{
47 uint16_t app_idx; /** AppKey Index. Used by client models */
48 uint16_t net_idx; /** NetKey Index. Used by client models */
49 uint32_t opcode; /** Opcode. Used by client models */
50 uint16_t src_addr; /** Source address. Not used by client models */
51 uint16_t dst_addr; /** Destination address. Not used by client models */
52 meshx_ptr_t p_ctx; /** Pointer to the context structure. Not used by client models */
54
55/**
56 * @brief Structure to hold provisioning parameters.
57 */
58typedef struct meshx_prov_params
59{
60 uint8_t *uuid; /**< UUID for the provisioning device */
61 uint8_t *node_name; /**< Node name for the provisioning device */
62 uint16_t freshboot_timeout_ms; /**< Fresh boot timeout in milliseconds */
64
65/**
66 * @brief Checks if a model is subscribed to a specific group address.
67 *
68 * This function determines whether the specified BLE Mesh model is subscribed
69 * to a given group address by utilizing the internal function
70 * esp_ble_mesh_is_model_subscribed_to_group.
71 *
72 * @param[in] p_model Pointer to the BLE Mesh model structure.
73 * @param[in] addr The group address to check for subscription.
74 *
75 * @return MESHX_SUCCESS if the model is subscribed to the group address,
76 * otherwise MESHX_FAIL.
77 */
79
80/**
81 * @brief Creates and initializes model and publication structures.
82 *
83 * This function allocates memory for model and publication structures
84 * based on the specified maximum number of elements. It initializes
85 * the provided pointers to point to the newly allocated memory.
86 *
87 * @param[out] p_pub Pointer to the publication structure to be created.
88 * @param[in] nmax Maximum number of elements for the model and publication.
89 *
90 * @return MESHX_SUCCESS on successful allocation and initialization,
91 * MESHX_INVALID_ARG if any input pointer is NULL,
92 * MESHX_NO_MEM if memory allocation fails.
93 */
95
96/**
97 * @brief Deletes the model and publication objects.
98 *
99 * This function frees the memory allocated for the model and publication
100 * objects pointed to by the provided pointers and sets them to NULL.
101 *
102 * @param[in,out] p_pub Pointer to the publication object to be deleted.
103 *
104 * @return MESHX_SUCCESS on successful deletion, MESHX_INVALID_ARG if
105 * either pointer is NULL.
106 */
108
109/**
110 * @brief Creates and initializes a generic client model for BLE Mesh.
111 *
112 * This function sets up the necessary structures and resources for a generic client model
113 * in the BLE Mesh stack. It initializes the model, publication context, and the on/off client instance.
114 *
115 * @param[in] p_model Pointer to the model structure to be initialized.
116 * @param[out] p_pub Pointer to a location where the address of the publication context will be stored.
117 * @param[out] p_cli Pointer to a location where the address of the on/off client instance will be stored.
118 * @param[in] model_id Model ID for the generic client model.
119 *
120 * @return meshx_err_t Returns an error code indicating the result of the operation.
121 * Typically, MESHX_OK on success or an appropriate error code on failure.
122 */
123meshx_err_t meshx_plat_client_create(meshx_ptr_t p_model, meshx_ptr_t* p_pub, meshx_ptr_t* p_cli, uint16_t model_id);
124
125/**
126 * @brief Deletes a generic client model from BLE Mesh.
127 *
128 * This function deletes a generic client model from the BLE Mesh stack,
129 * including the associated publication context and on/off client instance.
130 *
131 * @param[in] p_model Pointer to the model structure to be deleted.
132 * @param[out] p_pub Pointer to a location where the address of the publication context will be stored.
133 * @param[out] p_cli Pointer to a location where the address of the on/off client instance will be stored.
134 *
135 * @return meshx_err_t Returns an error code indicating the result of the operation.
136 * Typically, MESHX_OK on success or an appropriate error code on failure.
137 */
139
140/**
141 * @brief Retrieve the model ID of a generic server model.
142 *
143 * This function obtains the model ID associated with a specified generic server model.
144 *
145 * @param[in] p_model Pointer to the model whose ID is to be retrieved.
146 * @param[out] model_id Pointer to a variable where the retrieved model ID will be stored.
147 *
148 * @return MESHX_SUCCESS on success, or an appropriate error code on failure.
149 */
150meshx_err_t meshx_get_model_id(meshx_ptr_t p_model, uint16_t *model_id);
151
152/**
153 * @brief Creates a platform-specific BLE Mesh composition object.
154 *
155 * This function allocates memory for a MESHX_COMPOSITION object and assigns
156 * its pointer to the provided pointer argument. It checks for invalid
157 * arguments and memory allocation failures, returning appropriate error codes.
158 *
159 * @param[out] p_comp Pointer to the location where the composition object
160 * pointer will be stored.
161 *
162 * @return MESHX_SUCCESS on successful creation, MESHX_INVALID_ARG if the
163 * provided pointer is NULL, or MESHX_NO_MEM if memory allocation fails.
164 */
166
167/**
168 * @brief Adds an element to the BLE Mesh composition.
169 *
170 * This function adds a new element to the BLE Mesh composition at the specified
171 * index. It assigns the provided SIG and vendor models to the element and sets
172 * their respective counts.
173 *
174 * @param[in] index Index at which the element is to be added.
175 * @param[in,out] p_element_list Pointer to the list of elements.
176 * @param[in] p_sig_models Pointer to the SIG models to be assigned to the element.
177 * @param[in] p_ven_models Pointer to the vendor models to be assigned to the element.
178 * @param[in] sig_cnt Number of SIG models.
179 * @param[in] ven_cnt Number of vendor models.
180 *
181 * @return MESHX_SUCCESS on success, or MESHX_INVALID_ARG if the element list
182 * pointer is NULL.
183 */
185 uint16_t index,
186 meshx_ptr_t p_element_list,
187 meshx_ptr_t p_sig_models,
188 meshx_ptr_t p_ven_models,
189 uint8_t sig_cnt,
190 uint8_t ven_cnt);
191
192/**
193 * @brief Initializes a platform-specific BLE Mesh composition.
194 *
195 * This function sets up a BLE Mesh composition object with the specified
196 * company ID, product ID, and element index. It assigns the provided
197 * elements to the composition.
198 *
199 * @param[out] p_composition Pointer to the composition object to be initialized.
200 * @param[in] p_elements Pointer to the elements to be included in the composition.
201 * @param[in] cid Company ID for the composition.
202 * @param[in] pid Product ID for the composition.
203 * @param[in] element_idx Index of the element within the composition.
204 *
205 * @return MESHX_SUCCESS on successful initialization, or an appropriate error code on failure.
206 */
208 meshx_ptr_t p_composition,
209 meshx_ptr_t p_elements,
210 uint16_t cid,
211 uint16_t pid,
212 uint16_t element_idx);
213
214/**
215 * @brief Initializes the Bluetooth subsystem of the MeshX platform.
216 *
217 * This function sets up the Bluetooth-related components necessary for
218 * MeshX operation, such as BLE Mesh provisioning and communication.
219 *
220 * @param[in] uuid Pointer to the UUID address to be used for the Bluetooth initialization.
221 *
222 * @return meshx_err_t Returns MESHX_OK on success, or an appropriate error code.
223 */
225
226/**
227 * @brief Initializes the BLE Mesh stack with the given provisioning parameters.
228 *
229 * This function sets up the BLE Mesh stack and initializes it with the
230 * provided provisioning parameters.
231 *
232 * @param[in] prov_cfg Pointer to the provisioning parameters structure.
233 * @param[in] comp Pointer to the composition data.
234 *
235 * @return meshx_err_t Returns MESHX_OK on success, or an appropriate error code.
236 */
238
239/**
240 * @brief Retrieves the base element ID for the BLE Mesh platform.
241 *
242 * This function fetches the base element ID, which is used as a reference point
243 * for other elements in the BLE Mesh composition.
244 *
245 * @param[out] base_el_id Pointer to a variable where the base element ID will be stored.
246 *
247 * @return meshx_err_t Returns MESHX_SUCCESS on success, or an appropriate error code on failure.
248 */
250
251#ifdef __cplusplus
252}
253#endif
254
255#endif /* __MESHX_PLAT_SRV_CMN_H__ */
meshx_err_t meshx_plat_del_model_pub(meshx_ptr_t *p_pub)
Deletes the model and publication objects.
meshx_err_t meshx_plat_client_delete(meshx_ptr_t p_model, meshx_ptr_t *p_pub, meshx_ptr_t *p_cli)
Deletes a generic client model from BLE Mesh.
meshx_err_t meshx_plat_create_model_pub(meshx_ptr_t *p_pub, uint16_t nmax)
Creates and initializes model and publication structures.
meshx_err_t meshx_plat_add_element_to_composition(uint16_t index, meshx_ptr_t p_element_list, meshx_ptr_t p_sig_models, meshx_ptr_t p_ven_models, uint8_t sig_cnt, uint8_t ven_cnt)
Adds an element to the BLE Mesh composition.
meshx_err_t meshx_create_plat_composition(meshx_ptr_t *p_comp)
Creates a platform-specific BLE Mesh composition object.
meshx_err_t meshx_plat_client_create(meshx_ptr_t p_model, meshx_ptr_t *p_pub, meshx_ptr_t *p_cli, uint16_t model_id)
Creates and initializes a generic client model for BLE Mesh.
meshx_err_t meshx_platform_bt_init(meshx_uuid_addr_t uuid)
Initializes the Bluetooth subsystem of the MeshX platform.
meshx_err_t meshx_plat_composition_init(meshx_ptr_t p_composition, meshx_ptr_t p_elements, uint16_t cid, uint16_t pid, uint16_t element_idx)
Initializes a platform-specific BLE Mesh composition.
meshx_err_t meshx_get_model_id(meshx_ptr_t p_model, uint16_t *model_id)
Retrieve the model ID of a generic server model.
meshx_err_t meshx_is_group_subscribed(meshx_model_t *p_model, uint16_t addr)
Checks if a model is subscribed to a specific group address.
struct meshx_prov_params meshx_prov_params_t
Structure to hold provisioning parameters.
struct meshx_model meshx_model_t
meshx_err_t meshx_get_base_element_id(uint16_t *base_el_id)
Retrieves the base element ID for the BLE Mesh platform.
struct meshx_ctx meshx_ctx_t
Structure to hold context information for BLE Mesh operations.
meshx_err_t meshx_plat_ble_mesh_init(const meshx_prov_params_t *prov_cfg, meshx_ptr_t comp)
Initializes the BLE Mesh stack with the given provisioning parameters.
Common definitions for BLE Mesh models and opcodes in the MeshX framework.
void * meshx_ptr_t
Definition meshx_ble_mesh_cmn_def.h:636
uint8_t meshx_uuid_addr_t[16]
Definition meshx_ble_mesh_cmn_def.h:649
MeshX Error Codes.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
Platform abstraction layer for MeshX.
Structure to hold context information for BLE Mesh operations.
Definition meshx_ble_mesh_cmn.h:46
meshx_ptr_t p_ctx
Definition meshx_ble_mesh_cmn.h:52
uint16_t app_idx
Definition meshx_ble_mesh_cmn.h:47
uint32_t opcode
Definition meshx_ble_mesh_cmn.h:49
uint16_t net_idx
Definition meshx_ble_mesh_cmn.h:48
uint16_t src_addr
Definition meshx_ble_mesh_cmn.h:50
uint16_t dst_addr
Definition meshx_ble_mesh_cmn.h:51
Structure as Interface for meshx models.
Definition meshx_ble_mesh_cmn.h:35
meshx_ptr_t p_model
Definition meshx_ble_mesh_cmn.h:39
uint16_t pub_addr
Definition meshx_ble_mesh_cmn.h:38
uint16_t el_id
Definition meshx_ble_mesh_cmn.h:36
uint16_t model_id
Definition meshx_ble_mesh_cmn.h:37
Structure to hold provisioning parameters.
Definition meshx_ble_mesh_cmn.h:59
uint8_t * node_name
Definition meshx_ble_mesh_cmn.h:61
uint8_t * uuid
Definition meshx_ble_mesh_cmn.h:60
uint16_t freshboot_timeout_ms
Definition meshx_ble_mesh_cmn.h:62