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 File Reference

Common BLE Mesh interface definitions and utility functions. More...

#include "stdlib.h"
#include "string.h"
#include "meshx_err.h"
#include "meshx_ble_mesh_cmn_def.h"
#include "interface/meshx_platform.h"

Go to the source code of this file.

Data Structures

struct  meshx_model
 Structure as Interface for meshx models. More...
struct  meshx_ctx
 Structure to hold context information for BLE Mesh operations. More...
struct  meshx_prov_params
 Structure to hold provisioning parameters. More...

Typedefs

typedef struct meshx_model meshx_model_t
typedef struct meshx_ctx meshx_ctx_t
 Structure to hold context information for BLE Mesh operations.
typedef struct meshx_prov_params meshx_prov_params_t
 Structure to hold provisioning parameters.

Functions

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.
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_del_model_pub (meshx_ptr_t *p_pub)
 Deletes the model and publication objects.
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_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_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_create_plat_composition (meshx_ptr_t *p_comp)
 Creates a platform-specific BLE Mesh composition object.
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_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_platform_bt_init (meshx_uuid_addr_t uuid)
 Initializes the Bluetooth subsystem of the MeshX platform.
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.
meshx_err_t meshx_get_base_element_id (uint16_t *base_el_id)
 Retrieves the base element ID for the BLE Mesh platform.

Detailed Description

Common BLE Mesh interface definitions and utility functions.

Copyright (c) 2024 - 2025 MeshX

This header file contains the definitions and function declarations for managing BLE Mesh models, contexts, and compositions. It provides utilities for checking model subscriptions, creating and deleting model structures, retrieving model IDs, and managing BLE Mesh compositions.

The functions defined here facilitate the initialization, manipulation, and cleanup of BLE Mesh components, ensuring efficient memory management and error handling.

Author
Pranjal Chanda

Typedef Documentation

◆ meshx_ctx_t

typedef struct meshx_ctx meshx_ctx_t

Structure to hold context information for BLE Mesh operations.

◆ meshx_model_t

typedef struct meshx_model meshx_model_t

◆ meshx_prov_params_t

Structure to hold provisioning parameters.

Function Documentation

◆ meshx_create_plat_composition()

meshx_err_t meshx_create_plat_composition ( meshx_ptr_t * p_comp)

Creates a platform-specific BLE Mesh composition object.

This function allocates memory for a MESHX_COMPOSITION object and assigns its pointer to the provided pointer argument. It checks for invalid arguments and memory allocation failures, returning appropriate error codes.

Parameters
[out]p_compPointer to the location where the composition object pointer will be stored.
Returns
MESHX_SUCCESS on successful creation, MESHX_INVALID_ARG if the provided pointer is NULL, or MESHX_NO_MEM if memory allocation fails.

◆ meshx_get_base_element_id()

meshx_err_t meshx_get_base_element_id ( uint16_t * base_el_id)

Retrieves the base element ID for the BLE Mesh platform.

This function fetches the base element ID, which is used as a reference point for other elements in the BLE Mesh composition.

Parameters
[out]base_el_idPointer to a variable where the base element ID will be stored.
Returns
meshx_err_t Returns MESHX_SUCCESS on success, or an appropriate error code on failure.

◆ meshx_get_model_id()

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.

This function obtains the model ID associated with a specified generic server model.

Parameters
[in]p_modelPointer to the model whose ID is to be retrieved.
[out]model_idPointer to a variable where the retrieved model ID will be stored.
Returns
MESHX_SUCCESS on success, or an appropriate error code on failure.

◆ meshx_is_group_subscribed()

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.

This function determines whether the specified BLE Mesh model is subscribed to a given group address by utilizing the internal function esp_ble_mesh_is_model_subscribed_to_group.

Parameters
[in]p_modelPointer to the BLE Mesh model structure.
[in]addrThe group address to check for subscription.
Returns
MESHX_SUCCESS if the model is subscribed to the group address, otherwise MESHX_FAIL.

◆ meshx_plat_add_element_to_composition()

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.

This function adds a new element to the BLE Mesh composition at the specified index. It assigns the provided SIG and vendor models to the element and sets their respective counts.

Parameters
[in]indexIndex at which the element is to be added.
[in,out]p_element_listPointer to the list of elements.
[in]p_sig_modelsPointer to the SIG models to be assigned to the element.
[in]p_ven_modelsPointer to the vendor models to be assigned to the element.
[in]sig_cntNumber of SIG models.
[in]ven_cntNumber of vendor models.
Returns
MESHX_SUCCESS on success, or MESHX_INVALID_ARG if the element list pointer is NULL.

◆ meshx_plat_ble_mesh_init()

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.

This function sets up the BLE Mesh stack and initializes it with the provided provisioning parameters.

Parameters
[in]prov_cfgPointer to the provisioning parameters structure.
[in]compPointer to the composition data.
Returns
meshx_err_t Returns MESHX_OK on success, or an appropriate error code.

◆ meshx_plat_client_create()

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.

This function sets up the necessary structures and resources for a generic client model in the BLE Mesh stack. It initializes the model, publication context, and the on/off client instance.

Parameters
[in]p_modelPointer to the model structure to be initialized.
[out]p_pubPointer to a location where the address of the publication context will be stored.
[out]p_cliPointer to a location where the address of the on/off client instance will be stored.
[in]model_idModel ID for the generic client model.
Returns
meshx_err_t Returns an error code indicating the result of the operation. Typically, MESHX_OK on success or an appropriate error code on failure.

◆ meshx_plat_client_delete()

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.

This function deletes a generic client model from the BLE Mesh stack, including the associated publication context and on/off client instance.

Parameters
[in]p_modelPointer to the model structure to be deleted.
[out]p_pubPointer to a location where the address of the publication context will be stored.
[out]p_cliPointer to a location where the address of the on/off client instance will be stored.
Returns
meshx_err_t Returns an error code indicating the result of the operation. Typically, MESHX_OK on success or an appropriate error code on failure.

◆ meshx_plat_composition_init()

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.

This function sets up a BLE Mesh composition object with the specified company ID, product ID, and element index. It assigns the provided elements to the composition.

Parameters
[out]p_compositionPointer to the composition object to be initialized.
[in]p_elementsPointer to the elements to be included in the composition.
[in]cidCompany ID for the composition.
[in]pidProduct ID for the composition.
[in]element_idxIndex of the element within the composition.
Returns
MESHX_SUCCESS on successful initialization, or an appropriate error code on failure.

◆ meshx_plat_create_model_pub()

meshx_err_t meshx_plat_create_model_pub ( meshx_ptr_t * p_pub,
uint16_t nmax )

Creates and initializes model and publication structures.

This function allocates memory for model and publication structures based on the specified maximum number of elements. It initializes the provided pointers to point to the newly allocated memory.

Parameters
[out]p_pubPointer to the publication structure to be created.
[in]nmaxMaximum number of elements for the model and publication.
Returns
MESHX_SUCCESS on successful allocation and initialization, MESHX_INVALID_ARG if any input pointer is NULL, MESHX_NO_MEM if memory allocation fails.

◆ meshx_plat_del_model_pub()

meshx_err_t meshx_plat_del_model_pub ( meshx_ptr_t * p_pub)

Deletes the model and publication objects.

This function frees the memory allocated for the model and publication objects pointed to by the provided pointers and sets them to NULL.

Parameters
[in,out]p_pubPointer to the publication object to be deleted.
Returns
MESHX_SUCCESS on successful deletion, MESHX_INVALID_ARG if either pointer is NULL.

◆ meshx_platform_bt_init()

meshx_err_t meshx_platform_bt_init ( meshx_uuid_addr_t uuid)

Initializes the Bluetooth subsystem of the MeshX platform.

This function sets up the Bluetooth-related components necessary for MeshX operation, such as BLE Mesh provisioning and communication.

Parameters
[in]uuidPointer to the UUID address to be used for the Bluetooth initialization.
Returns
meshx_err_t Returns MESHX_OK on success, or an appropriate error code.