MeshX 0.3
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
esp_cfg_srv_model.c File Reference

Implementation of the BLE Mesh Configuration Server for the MeshX platform. This file contains the initialization, callback handling, and utility functions for managing the BLE Mesh Configuration Server model. More...

Include dependency graph for esp_cfg_srv_model.c:

Go to the source code of this file.

Functions

static void meshx_ble_mesh_config_server_cb (esp_ble_mesh_cfg_server_cb_event_t event, const esp_ble_mesh_cfg_server_cb_param_t *param)
 BLE Mesh Configuration Server callback function.
 
meshx_err_t meshx_plat_config_srv_init (void)
 Initializes the MeshX platform configuration server.
 
meshx_err_t meshx_plat_get_config_srv_instance (meshx_ptr_t *p_conf_srv)
 Retrieve the instance of the BLE Mesh configuration server.
 
meshx_err_t meshx_plat_get_config_srv_model (meshx_ptr_t p_model)
 Retrieves the configuration server model for the BLE Mesh.
 

Variables

static MESHX_CFG_SRV meshx_config_server_instance
 
static MESHX_MODEL meshx_config_server_model
 

Detailed Description

Implementation of the BLE Mesh Configuration Server for the MeshX platform. This file contains the initialization, callback handling, and utility functions for managing the BLE Mesh Configuration Server model.

Copyright (c) 2024 - 2025 MeshX

The Configuration Server is responsible for handling configuration messages such as adding keys, setting publication parameters, and managing subscriptions. It provides an interface for the application to interact with the BLE Mesh stack.

Author
Pranjal Chanda

Definition in file esp_cfg_srv_model.c.

Function Documentation

◆ meshx_ble_mesh_config_server_cb()

static void meshx_ble_mesh_config_server_cb ( esp_ble_mesh_cfg_server_cb_event_t event,
const esp_ble_mesh_cfg_server_cb_param_t * param )
static

BLE Mesh Configuration Server callback function.

Handles state change events and dispatches them to the appropriate callbacks registered with the configuration server.

Parameters
[in]eventConfiguration server event type.
[in]paramPointer to the BLE Mesh Configuration Server callback parameters.

Definition at line 54 of file esp_cfg_srv_model.c.

56{
57 if (event != ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT)
58 return;
59
61 {
62 .ctx =
63 {
64 .net_idx = param->ctx.net_idx,
65 .app_idx = param->ctx.app_idx,
66 .dst_addr = param->ctx.recv_dst,
67 .src_addr = param->ctx.addr,
68 .opcode = param->ctx.recv_op,
69 .p_ctx = (meshx_ptr_t) &param->ctx
70 },
71 .model =
72 {
73 .model_id = param->model->model_id,
74 .el_id = param->model->element_idx,
75 .p_model = param->model
76 }
77 };
78 MESHX_LOGD(MODULE_ID_MODEL_SERVER, "ele: %d", pub_param.model.el_id);
79 /* Copy all the status msg from the BLE layer */
80 memcpy(&pub_param.state_change,
81 &param->value.state_change,
83
87 &pub_param,
88 sizeof(pub_param));
89 if (err)
90 {
91 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Error publishing control task msg (Err: 0x%x)", err);
92 }
93}
void * meshx_ptr_t
#define MESHX_MODEL_ID_CONFIG_SRV
BLE Mesh models related Model ID and Opcode definitions.
struct meshx_config_srv_cb_param meshx_config_srv_cb_param_t
@ CONTROL_TASK_MSG_CODE_FRM_BLE
meshx_err_t control_task_msg_publish(control_task_msg_code_t msg_code, control_task_msg_evt_t msg_evt, const void *msg_evt_params, size_t sizeof_msg_evt_params)
Publish a control task message.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:73
#define MESHX_LOGD(module_id, format,...)
Definition meshx_log.h:113
@ MODULE_ID_MODEL_SERVER
Definition module_id.h:30
meshx_cfg_srv_state_change_t state_change
Configuration Server model state change value union.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_plat_config_srv_init()

meshx_err_t meshx_plat_config_srv_init ( void )

Initializes the MeshX platform configuration server.

This function sets up the necessary resources and configurations for the MeshX BLE Mesh configuration server. It should be called during the initialization phase of the application to ensure proper operation of the MeshX BLE Mesh stack.

Returns
  • MESHX_SUCCESS on successful initialization.
  • Appropriate error code from meshx_err_t on failure.

Definition at line 95 of file esp_cfg_srv_model.c.

96{
97 esp_err_t err = esp_ble_mesh_register_config_server_callback(
98 (esp_ble_mesh_cfg_server_cb_t)&meshx_ble_mesh_config_server_cb);
99 if (err)
100 {
101 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Error plat registering config server (Err: 0x%x)", err);
102 return MESHX_ERR_PLAT;
103 }
104 return MESHX_SUCCESS;
105}
static void meshx_ble_mesh_config_server_cb(esp_ble_mesh_cfg_server_cb_event_t event, const esp_ble_mesh_cfg_server_cb_param_t *param)
BLE Mesh Configuration Server callback function.
@ MESHX_SUCCESS
Definition meshx_err.h:40
@ MESHX_ERR_PLAT
Definition meshx_err.h:43
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_plat_get_config_srv_instance()

meshx_err_t meshx_plat_get_config_srv_instance ( meshx_ptr_t * p_conf_srv)

Retrieve the instance of the BLE Mesh configuration server.

This function provides access to the BLE Mesh configuration server instance.

Parameters
[out]p_conf_srvPointer to a variable where the configuration server instance will be stored. The caller must ensure that the pointer is valid and non-NULL.
Returns
  • MESHX_SUCCESS on success.
  • Appropriate error code from meshx_err_t on failure.

Definition at line 107 of file esp_cfg_srv_model.c.

108{
109 if (p_conf_srv == NULL)
110 {
111 return MESHX_INVALID_ARG;
112 }
113 /* Return the pointer to the configuration server instance */
114 *p_conf_srv = &meshx_config_server_instance;
115
116 return MESHX_SUCCESS;
117}
static MESHX_CFG_SRV meshx_config_server_instance
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
Here is the caller graph for this function:

◆ meshx_plat_get_config_srv_model()

meshx_err_t meshx_plat_get_config_srv_model ( meshx_ptr_t p_model)

Retrieves the configuration server model for the BLE Mesh.

This function provides access to the configuration server model used in the BLE Mesh implementation. The retrieved model can be used for configuring and managing the mesh network.

Parameters
[out]p_modelPointer to a variable where the address of the configuration server model will be stored. The caller must ensure that the pointer is valid.
Returns
  • MESHX_SUCCESS on success.
  • Appropriate error code from meshx_err_t on failure.

Definition at line 119 of file esp_cfg_srv_model.c.

120{
121 if (p_model == NULL)
122 {
123 return MESHX_INVALID_ARG;
124 }
125 /* Return the pointer to the configuration server model */
126 memcpy(p_model, &meshx_config_server_model, sizeof(meshx_config_server_model));
127 return MESHX_SUCCESS;
128}
static MESHX_MODEL meshx_config_server_model
Here is the caller graph for this function:

Variable Documentation

◆ meshx_config_server_instance

MESHX_CFG_SRV meshx_config_server_instance
static
Initial value:
= {
.net_transmit = ESP_BLE_MESH_TRANSMIT(2, 20),
.relay = ESP_BLE_MESH_RELAY_ENABLED,
.relay_retransmit = ESP_BLE_MESH_TRANSMIT(2, 20),
.beacon = ESP_BLE_MESH_BEACON_ENABLED,
.gatt_proxy = ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED,
.friend_state = ESP_BLE_MESH_FRIEND_NOT_SUPPORTED,
.default_ttl = 7,
}

Definition at line 19 of file esp_cfg_srv_model.c.

19 {
20 /* 3 transmissions with 20ms interval */
21 .net_transmit = ESP_BLE_MESH_TRANSMIT(2, 20),
22 .relay = ESP_BLE_MESH_RELAY_ENABLED,
23 .relay_retransmit = ESP_BLE_MESH_TRANSMIT(2, 20),
24 .beacon = ESP_BLE_MESH_BEACON_ENABLED,
25#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
26 .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_ENABLED,
27#else
28 .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED,
29#endif
30#if defined(CONFIG_BLE_MESH_FRIEND)
31 .friend_state = ESP_BLE_MESH_FRIEND_ENABLED,
32#else
33 .friend_state = ESP_BLE_MESH_FRIEND_NOT_SUPPORTED,
34#endif
35 .default_ttl = 7,
36};

◆ meshx_config_server_model

MESHX_MODEL meshx_config_server_model
static
Initial value:
= {
.keys = ESP_BLE_MESH_MODEL_KEYS_UNUSED,
.groups = ESP_BLE_MESH_MODEL_GROUPS_UNASSIGNED,
}

Definition at line 38 of file esp_cfg_srv_model.c.

38 {
39 .model_id = MESHX_MODEL_ID_CONFIG_SRV,
40 .user_data = &meshx_config_server_instance,
41 .keys = ESP_BLE_MESH_MODEL_KEYS_UNUSED,
42 .groups = ESP_BLE_MESH_MODEL_GROUPS_UNASSIGNED,
43};