Fork ESP-IDF's bluetooth component
i want better sbc encoding, and no cla will stop me
This commit is contained in:
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "btc_ble_mesh_ble.h"
|
||||
#include "adv.h"
|
||||
#include "scan.h"
|
||||
#include "mesh/adapter.h"
|
||||
#include "esp_ble_mesh_ble_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
|
||||
|
||||
static void btc_ble_mesh_ble_copy_req_data(btc_msg_t *msg, void *p_dst, void *p_src)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
esp_ble_mesh_ble_cb_param_t *p_dst_data = (esp_ble_mesh_ble_cb_param_t *)p_dst;
|
||||
esp_ble_mesh_ble_cb_param_t *p_src_data = (esp_ble_mesh_ble_cb_param_t *)p_src;
|
||||
|
||||
if (!msg || !p_src_data || !p_dst_data) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT:
|
||||
if (p_src_data->scan_ble_adv_pkt.data && p_src_data->scan_ble_adv_pkt.length) {
|
||||
p_dst_data->scan_ble_adv_pkt.length = p_src_data->scan_ble_adv_pkt.length;
|
||||
p_dst_data->scan_ble_adv_pkt.data = bt_mesh_calloc(p_src_data->scan_ble_adv_pkt.length);
|
||||
if (p_dst_data->scan_ble_adv_pkt.data) {
|
||||
memcpy(p_dst_data->scan_ble_adv_pkt.data, p_src_data->scan_ble_adv_pkt.data,
|
||||
p_src_data->scan_ble_adv_pkt.length);
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_ble_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
esp_ble_mesh_ble_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_ble_cb_param_t *)msg->arg;
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT:
|
||||
if (arg->scan_ble_adv_pkt.data) {
|
||||
bt_mesh_free(arg->scan_ble_adv_pkt.data);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_ble_callback(esp_ble_mesh_ble_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_BLE_MESH_BLE_COEX)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_BLE_MESH_BLE_COEX;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_ble_cb_param_t),
|
||||
btc_ble_mesh_ble_copy_req_data, btc_ble_mesh_ble_free_req_data);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
void bt_mesh_ble_scan_cb_evt_to_btc(const bt_mesh_addr_t *addr,
|
||||
uint8_t adv_type, uint8_t data[],
|
||||
uint16_t length, int8_t rssi)
|
||||
{
|
||||
esp_ble_mesh_ble_cb_param_t param = {0};
|
||||
|
||||
if (addr == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(param.scan_ble_adv_pkt.addr, addr->val, sizeof(addr->val));
|
||||
param.scan_ble_adv_pkt.addr_type = addr->type;
|
||||
if (data && length) {
|
||||
param.scan_ble_adv_pkt.data = data;
|
||||
param.scan_ble_adv_pkt.length = length;
|
||||
}
|
||||
param.scan_ble_adv_pkt.adv_type = adv_type;
|
||||
param.scan_ble_adv_pkt.rssi = rssi;
|
||||
|
||||
btc_ble_mesh_ble_callback(¶m, ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
||||
|
||||
void btc_ble_mesh_ble_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_ble_cb_param_t param = {0};
|
||||
btc_ble_mesh_ble_args_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_ble_args_t *)msg->arg;
|
||||
|
||||
switch (msg->act) {
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
case BTC_BLE_MESH_ACT_START_BLE_ADV: {
|
||||
struct bt_mesh_ble_adv_param *set = (struct bt_mesh_ble_adv_param *)&arg->start_ble_adv.param;
|
||||
struct bt_mesh_ble_adv_data *data = NULL;
|
||||
if (arg->start_ble_adv.data.adv_data_len || arg->start_ble_adv.data.scan_rsp_data_len) {
|
||||
data = (struct bt_mesh_ble_adv_data *)&arg->start_ble_adv.data;
|
||||
}
|
||||
|
||||
param.start_ble_advertising_comp.err_code =
|
||||
bt_mesh_start_ble_advertising(set, data, ¶m.start_ble_advertising_comp.index);
|
||||
|
||||
btc_ble_mesh_ble_callback(¶m, ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT);
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_STOP_BLE_ADV:
|
||||
param.stop_ble_advertising_comp.index = arg->stop_ble_adv.index;
|
||||
param.stop_ble_advertising_comp.err_code =
|
||||
bt_mesh_stop_ble_advertising(arg->stop_ble_adv.index);
|
||||
|
||||
btc_ble_mesh_ble_callback(¶m, ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT);
|
||||
break;
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
case BTC_BLE_MESH_ACT_START_BLE_SCAN:
|
||||
param.start_ble_scan_comp.err_code =
|
||||
bt_mesh_start_ble_scan((struct bt_mesh_ble_scan_param *)&arg->start_ble_scan.param);
|
||||
btc_ble_mesh_ble_callback(¶m, ESP_BLE_MESH_START_BLE_SCANNING_COMP_EVT);
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_STOP_BLE_SCAN:
|
||||
param.stop_ble_scan_comp.err_code = bt_mesh_stop_ble_scan();
|
||||
btc_ble_mesh_ble_callback(¶m, ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT);
|
||||
break;
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void btc_ble_mesh_ble_cb_to_app(esp_ble_mesh_ble_cb_event_t event,
|
||||
esp_ble_mesh_ble_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_ble_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_ble_cb_t)btc_profile_cb_get(BTC_PID_BLE_MESH_BLE_COEX);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_ble_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_ble_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_ble_cb_param_t *)msg->arg;
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_BLE_EVT_MAX) {
|
||||
btc_ble_mesh_ble_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_ble_free_req_data(msg);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */
|
||||
@@ -0,0 +1,736 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc_ble_mesh_model_common.h"
|
||||
#include "btc_ble_mesh_config_model.h"
|
||||
#include "esp_ble_mesh_config_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_CFG_CLI
|
||||
#include "mesh/cfg_cli.h"
|
||||
|
||||
/* Configuration Client Model related functions */
|
||||
|
||||
static inline void btc_ble_mesh_config_client_cb_to_app(esp_ble_mesh_cfg_client_cb_event_t event,
|
||||
esp_ble_mesh_cfg_client_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_cfg_client_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_cfg_client_cb_t)btc_profile_cb_get(BTC_PID_CONFIG_CLIENT);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
btc_ble_mesh_config_client_args_t *dst = (btc_ble_mesh_config_client_args_t *)p_dest;
|
||||
btc_ble_mesh_config_client_args_t *src = (btc_ble_mesh_config_client_args_t *)p_src;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: {
|
||||
dst->cfg_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->cfg_client_get_state.params) {
|
||||
memcpy(dst->cfg_client_get_state.params, src->cfg_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->cfg_client_get_state.get_state) {
|
||||
dst->cfg_client_get_state.get_state = (esp_ble_mesh_cfg_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_cfg_client_get_state_t));
|
||||
if (dst->cfg_client_get_state.get_state) {
|
||||
memcpy(dst->cfg_client_get_state.get_state, src->cfg_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_cfg_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: {
|
||||
dst->cfg_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->cfg_client_set_state.params) {
|
||||
memcpy(dst->cfg_client_set_state.params, src->cfg_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->cfg_client_set_state.set_state) {
|
||||
dst->cfg_client_set_state.set_state = (esp_ble_mesh_cfg_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_cfg_client_set_state_t));
|
||||
if (dst->cfg_client_set_state.set_state) {
|
||||
memcpy(dst->cfg_client_set_state.set_state, src->cfg_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_cfg_client_set_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BT_DBG("%s, Unknown act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_config_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_config_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_config_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE:
|
||||
if (arg->cfg_client_get_state.params) {
|
||||
bt_mesh_free(arg->cfg_client_get_state.params);
|
||||
}
|
||||
if (arg->cfg_client_get_state.get_state) {
|
||||
bt_mesh_free(arg->cfg_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE:
|
||||
if (arg->cfg_client_set_state.params) {
|
||||
bt_mesh_free(arg->cfg_client_set_state.params);
|
||||
}
|
||||
if (arg->cfg_client_set_state.set_state) {
|
||||
bt_mesh_free(arg->cfg_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_cfg_client_cb_param_t *p_dest_data = (esp_ble_mesh_cfg_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_cfg_client_cb_param_t *p_src_data = (esp_ble_mesh_cfg_client_cb_param_t *)p_src;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT:
|
||||
if (p_src_data->params) {
|
||||
switch (p_src_data->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_STATUS:
|
||||
if (p_src_data->status_cb.comp_data_status.composition_data) {
|
||||
length = p_src_data->status_cb.comp_data_status.composition_data->len;
|
||||
p_dest_data->status_cb.comp_data_status.composition_data = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.comp_data_status.composition_data) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.comp_data_status.composition_data,
|
||||
p_src_data->status_cb.comp_data_status.composition_data->data,
|
||||
p_src_data->status_cb.comp_data_status.composition_data->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_LIST:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_LIST:
|
||||
if (p_src_data->status_cb.model_sub_list.sub_addr) {
|
||||
length = p_src_data->status_cb.model_sub_list.sub_addr->len;
|
||||
p_dest_data->status_cb.model_sub_list.sub_addr = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.model_sub_list.sub_addr) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.model_sub_list.sub_addr,
|
||||
p_src_data->status_cb.model_sub_list.sub_addr->data,
|
||||
p_src_data->status_cb.model_sub_list.sub_addr->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_LIST:
|
||||
if (p_src_data->status_cb.netkey_list.net_idx) {
|
||||
length = p_src_data->status_cb.netkey_list.net_idx->len;
|
||||
p_dest_data->status_cb.netkey_list.net_idx = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.netkey_list.net_idx) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.netkey_list.net_idx,
|
||||
p_src_data->status_cb.netkey_list.net_idx->data,
|
||||
p_src_data->status_cb.netkey_list.net_idx->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_LIST:
|
||||
if (p_src_data->status_cb.appkey_list.app_idx) {
|
||||
length = p_src_data->status_cb.appkey_list.app_idx->len;
|
||||
p_dest_data->status_cb.appkey_list.app_idx = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.appkey_list.app_idx) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.appkey_list.app_idx,
|
||||
p_src_data->status_cb.appkey_list.app_idx->data,
|
||||
p_src_data->status_cb.appkey_list.app_idx->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_LIST:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_LIST:
|
||||
if (p_src_data->status_cb.model_app_list.app_idx) {
|
||||
length = p_src_data->status_cb.model_app_list.app_idx->len;
|
||||
p_dest_data->status_cb.model_app_list.app_idx = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.model_app_list.app_idx) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.model_app_list.app_idx,
|
||||
p_src_data->status_cb.model_app_list.app_idx->data,
|
||||
p_src_data->status_cb.model_app_list.app_idx->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_config_client_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_cfg_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_cfg_client_cb_param_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT:
|
||||
if (arg->params) {
|
||||
switch (arg->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.comp_data_status.composition_data);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_LIST:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_LIST:
|
||||
bt_mesh_free_buf(arg->status_cb.model_sub_list.sub_addr);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_LIST:
|
||||
bt_mesh_free_buf(arg->status_cb.netkey_list.net_idx);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_LIST:
|
||||
bt_mesh_free_buf(arg->status_cb.appkey_list.app_idx);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_LIST:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_LIST:
|
||||
bt_mesh_free_buf(arg->status_cb.model_app_list.app_idx);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_config_client_callback(esp_ble_mesh_cfg_client_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_CONFIG_CLIENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_CONFIG_CLIENT;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_cfg_client_cb_param_t),
|
||||
btc_ble_mesh_config_client_copy_req_data, btc_ble_mesh_config_client_free_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_config_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_cfg_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx || len > sizeof(cb_params.status_cb)) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_CONFIG_CLIENT_GET_STATE:
|
||||
act = ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_CONFIG_CLIENT_SET_STATE:
|
||||
act = ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH:
|
||||
act = ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT:
|
||||
act = ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
BT_ERR("Unknown Config client event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
params.opcode = opcode;
|
||||
params.model = (esp_ble_mesh_model_t *)model;
|
||||
params.ctx.net_idx = ctx->net_idx;
|
||||
params.ctx.app_idx = ctx->app_idx;
|
||||
params.ctx.addr = ctx->addr;
|
||||
params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
params.ctx.recv_op = ctx->recv_op;
|
||||
params.ctx.recv_dst = ctx->recv_dst;
|
||||
params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
cb_params.error_code = 0;
|
||||
cb_params.params = ¶ms;
|
||||
|
||||
if (val && len) {
|
||||
memcpy(&cb_params.status_cb, val, len);
|
||||
}
|
||||
|
||||
btc_ble_mesh_config_client_callback(&cb_params, act);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_config_client_publish_callback(uint32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_config_client_cb_evt_to_btc(opcode, BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH,
|
||||
model, ctx, buf->data, buf->len);
|
||||
}
|
||||
|
||||
static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_cfg_client_get_state_t *get)
|
||||
{
|
||||
bt_mesh_client_common_param_t param = {0};
|
||||
|
||||
if (params == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
switch (params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET:
|
||||
if (get == NULL) {
|
||||
BT_ERR("Invalid Configuration Get");
|
||||
return -EINVAL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
btc_ble_mesh_set_client_common_param(params, ¶m, true);
|
||||
|
||||
switch (param.opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_BEACON_GET:
|
||||
return bt_mesh_cfg_beacon_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_GET:
|
||||
return bt_mesh_cfg_ttl_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_FRIEND_GET:
|
||||
return bt_mesh_cfg_friend_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_GET:
|
||||
return bt_mesh_cfg_gatt_proxy_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_RELAY_GET:
|
||||
return bt_mesh_cfg_relay_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET:
|
||||
return bt_mesh_cfg_mod_pub_get(¶m, get->model_pub_get.element_addr,
|
||||
get->model_pub_get.model_id,
|
||||
get->model_pub_get.company_id);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_GET:
|
||||
return bt_mesh_cfg_hb_pub_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_GET:
|
||||
return bt_mesh_cfg_hb_sub_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
|
||||
return bt_mesh_cfg_comp_data_get(¶m, get->comp_data_get.page);
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
|
||||
return bt_mesh_cfg_mod_sub_get(¶m, get->sig_model_sub_get.element_addr,
|
||||
get->sig_model_sub_get.model_id);
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET:
|
||||
return bt_mesh_cfg_mod_sub_get_vnd(¶m, get->vnd_model_sub_get.element_addr,
|
||||
get->vnd_model_sub_get.model_id,
|
||||
get->vnd_model_sub_get.company_id);
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_GET:
|
||||
return bt_mesh_cfg_net_key_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
|
||||
return bt_mesh_cfg_app_key_get(¶m, get->app_key_get.net_idx);
|
||||
case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET:
|
||||
return bt_mesh_cfg_node_identity_get(¶m, get->node_identity_get.net_idx);
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET:
|
||||
return bt_mesh_cfg_mod_app_get(¶m, get->sig_model_app_get.element_addr,
|
||||
get->sig_model_app_get.model_id);
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET:
|
||||
return bt_mesh_cfg_mod_app_get_vnd(¶m, get->vnd_model_app_get.element_addr,
|
||||
get->vnd_model_app_get.model_id,
|
||||
get->vnd_model_app_get.company_id);
|
||||
case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_GET:
|
||||
return bt_mesh_cfg_kr_phase_get(¶m, get->kr_phase_get.net_idx);
|
||||
case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET:
|
||||
return bt_mesh_cfg_lpn_timeout_get(¶m, get->lpn_pollto_get.lpn_addr);
|
||||
case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_GET:
|
||||
return bt_mesh_cfg_net_transmit_get(¶m);
|
||||
default:
|
||||
BT_ERR("Invalid Configuration Get opcode 0x%04x", param.opcode);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_cfg_client_set_state_t *set)
|
||||
{
|
||||
bt_mesh_client_common_param_t param = {0};
|
||||
|
||||
if (params == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (params->opcode != ESP_BLE_MESH_MODEL_OP_NODE_RESET && set == NULL) {
|
||||
BT_ERR("Invalid Configuration Set");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
btc_ble_mesh_set_client_common_param(params, ¶m, true);
|
||||
|
||||
switch (param.opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_BEACON_SET:
|
||||
return bt_mesh_cfg_beacon_set(¶m, set->beacon_set.beacon);
|
||||
case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_SET:
|
||||
return bt_mesh_cfg_ttl_set(¶m, set->default_ttl_set.ttl);
|
||||
case ESP_BLE_MESH_MODEL_OP_FRIEND_SET:
|
||||
return bt_mesh_cfg_friend_set(¶m, set->friend_set.friend_state);
|
||||
case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_SET:
|
||||
return bt_mesh_cfg_gatt_proxy_set(¶m, set->gatt_proxy_set.gatt_proxy);
|
||||
case ESP_BLE_MESH_MODEL_OP_RELAY_SET:
|
||||
return bt_mesh_cfg_relay_set(¶m, set->relay_set.relay,
|
||||
set->relay_set.relay_retransmit);
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_ADD:
|
||||
return bt_mesh_cfg_net_key_add(¶m, set->net_key_add.net_idx,
|
||||
&set->net_key_add.net_key[0]);
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD:
|
||||
return bt_mesh_cfg_app_key_add(¶m, set->app_key_add.net_idx,
|
||||
set->app_key_add.app_idx,
|
||||
&set->app_key_add.app_key[0]);
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_APP_BIND:
|
||||
return bt_mesh_cfg_mod_app_bind(¶m, set->model_app_bind.element_addr,
|
||||
set->model_app_bind.model_app_idx,
|
||||
set->model_app_bind.model_id,
|
||||
set->model_app_bind.company_id);
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_SET: {
|
||||
struct bt_mesh_cfg_mod_pub model_pub = {
|
||||
.addr = set->model_pub_set.publish_addr,
|
||||
.app_idx = set->model_pub_set.publish_app_idx,
|
||||
.cred_flag = set->model_pub_set.cred_flag,
|
||||
.ttl = set->model_pub_set.publish_ttl,
|
||||
.period = set->model_pub_set.publish_period,
|
||||
.transmit = set->model_pub_set.publish_retransmit,
|
||||
};
|
||||
return bt_mesh_cfg_mod_pub_set(¶m, set->model_pub_set.element_addr,
|
||||
set->model_pub_set.model_id,
|
||||
set->model_pub_set.company_id, &model_pub);
|
||||
}
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_ADD:
|
||||
return bt_mesh_cfg_mod_sub_add(¶m, set->model_sub_add.element_addr,
|
||||
set->model_sub_add.sub_addr,
|
||||
set->model_sub_add.model_id,
|
||||
set->model_sub_add.company_id);
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE:
|
||||
return bt_mesh_cfg_mod_sub_del(¶m, set->model_sub_delete.element_addr,
|
||||
set->model_sub_delete.sub_addr,
|
||||
set->model_sub_delete.model_id,
|
||||
set->model_sub_delete.company_id);
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_OVERWRITE:
|
||||
return bt_mesh_cfg_mod_sub_overwrite(¶m, set->model_sub_overwrite.element_addr,
|
||||
set->model_sub_overwrite.sub_addr,
|
||||
set->model_sub_overwrite.model_id,
|
||||
set->model_sub_overwrite.company_id);
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_ADD:
|
||||
return bt_mesh_cfg_mod_sub_va_add(¶m, set->model_sub_va_add.element_addr,
|
||||
&set->model_sub_va_add.label_uuid[0],
|
||||
set->model_sub_va_add.model_id,
|
||||
set->model_sub_va_add.company_id);
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_OVERWRITE:
|
||||
return bt_mesh_cfg_mod_sub_va_overwrite(¶m, set->model_sub_va_overwrite.element_addr,
|
||||
&set->model_sub_va_overwrite.label_uuid[0],
|
||||
set->model_sub_va_overwrite.model_id,
|
||||
set->model_sub_va_overwrite.company_id);
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_DELETE:
|
||||
return bt_mesh_cfg_mod_sub_va_del(¶m, set->model_sub_va_delete.element_addr,
|
||||
&set->model_sub_va_delete.label_uuid[0],
|
||||
set->model_sub_va_delete.model_id,
|
||||
set->model_sub_va_delete.company_id);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_SET:
|
||||
return bt_mesh_cfg_hb_sub_set(¶m, (struct bt_mesh_cfg_hb_sub *)&set->heartbeat_sub_set);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_SET:
|
||||
return bt_mesh_cfg_hb_pub_set(¶m, (struct bt_mesh_cfg_hb_pub *)&set->heartbeat_pub_set);
|
||||
case ESP_BLE_MESH_MODEL_OP_NODE_RESET:
|
||||
return bt_mesh_cfg_node_reset(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_VIRTUAL_ADDR_SET: {
|
||||
struct bt_mesh_cfg_mod_pub model_pub = {
|
||||
.app_idx = set->model_pub_va_set.publish_app_idx,
|
||||
.cred_flag = set->model_pub_va_set.cred_flag,
|
||||
.ttl = set->model_pub_va_set.publish_ttl,
|
||||
.period = set->model_pub_va_set.publish_period,
|
||||
.transmit = set->model_pub_va_set.publish_retransmit,
|
||||
};
|
||||
return bt_mesh_cfg_mod_pub_va_set(¶m, set->model_pub_va_set.element_addr,
|
||||
set->model_pub_va_set.model_id,
|
||||
set->model_pub_va_set.company_id,
|
||||
set->model_pub_va_set.label_uuid, &model_pub);
|
||||
}
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE_ALL:
|
||||
return bt_mesh_cfg_mod_sub_del_all(¶m, set->model_sub_delete_all.element_addr,
|
||||
set->model_sub_delete_all.model_id,
|
||||
set->model_sub_delete_all.company_id);
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_UPDATE:
|
||||
return bt_mesh_cfg_net_key_update(¶m, set->net_key_update.net_idx,
|
||||
set->net_key_update.net_key);
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_DELETE:
|
||||
return bt_mesh_cfg_net_key_delete(¶m, set->net_key_delete.net_idx);
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_UPDATE:
|
||||
return bt_mesh_cfg_app_key_update(¶m, set->app_key_update.net_idx,
|
||||
set->app_key_update.app_idx,
|
||||
set->app_key_update.app_key);
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_DELETE:
|
||||
return bt_mesh_cfg_app_key_delete(¶m, set->app_key_delete.net_idx,
|
||||
set->app_key_delete.app_idx);
|
||||
case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_SET:
|
||||
return bt_mesh_cfg_node_identity_set(¶m, set->node_identity_set.net_idx,
|
||||
set->node_identity_set.identity);
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_APP_UNBIND:
|
||||
return bt_mesh_cfg_mod_app_unbind(¶m, set->model_app_unbind.element_addr,
|
||||
set->model_app_unbind.model_app_idx,
|
||||
set->model_app_unbind.model_id,
|
||||
set->model_app_unbind.company_id);
|
||||
case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_SET:
|
||||
return bt_mesh_cfg_kr_phase_set(¶m, set->kr_phase_set.net_idx,
|
||||
set->kr_phase_set.transition);
|
||||
case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_SET:
|
||||
return bt_mesh_cfg_net_transmit_set(¶m, set->net_transmit_set.net_transmit);
|
||||
default:
|
||||
BT_ERR("Invalid Configuration Set opcode 0x%04x", param.opcode);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_config_client_args_t *arg = NULL;
|
||||
esp_ble_mesh_cfg_client_cb_param_t cb = {0};
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_config_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: {
|
||||
cb.params = arg->cfg_client_get_state.params;
|
||||
cb.error_code = btc_ble_mesh_config_client_get_state(arg->cfg_client_get_state.params,
|
||||
arg->cfg_client_get_state.get_state);
|
||||
if (cb.error_code) {
|
||||
btc_ble_mesh_config_client_callback(&cb, ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: {
|
||||
cb.params = arg->cfg_client_set_state.params;
|
||||
cb.error_code = btc_ble_mesh_config_client_set_state(arg->cfg_client_set_state.params,
|
||||
arg->cfg_client_set_state.set_state);
|
||||
if (cb.error_code) {
|
||||
btc_ble_mesh_config_client_callback(&cb, ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
btc_ble_mesh_config_client_arg_deep_free(msg);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_cfg_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_cfg_client_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_CFG_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_config_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_config_client_free_req_data(msg);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_CFG_CLI */
|
||||
|
||||
/* Configuration Server Model related functions */
|
||||
|
||||
static inline void btc_ble_mesh_config_server_cb_to_app(esp_ble_mesh_cfg_server_cb_event_t event,
|
||||
esp_ble_mesh_cfg_server_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_cfg_server_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_cfg_server_cb_t)btc_profile_cb_get(BTC_PID_CONFIG_SERVER);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_config_server_callback(esp_ble_mesh_cfg_server_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_CONFIG_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_CONFIG_SERVER;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_cfg_server_cb_param_t), NULL, NULL);
|
||||
}
|
||||
|
||||
void bt_mesh_config_server_cb_evt_to_btc(uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_cfg_server_cb_param_t cb_params = {0};
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx || len > sizeof(cb_params.value)) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE:
|
||||
act = ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT;
|
||||
break;
|
||||
default:
|
||||
BT_ERR("Unknown Config server event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
cb_params.model = (esp_ble_mesh_model_t *)model;
|
||||
cb_params.ctx.net_idx = ctx->net_idx;
|
||||
cb_params.ctx.app_idx = ctx->app_idx;
|
||||
cb_params.ctx.addr = ctx->addr;
|
||||
cb_params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
cb_params.ctx.recv_op = ctx->recv_op;
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
cb_params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
cb_params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
if (val && len) {
|
||||
memcpy(&cb_params.value, val, len);
|
||||
}
|
||||
|
||||
btc_ble_mesh_config_server_callback(&cb_params, act);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_cfg_server_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_cfg_server_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_CFG_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_config_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,731 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc_ble_mesh_model_common.h"
|
||||
#include "btc_ble_mesh_generic_model.h"
|
||||
#include "esp_ble_mesh_generic_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_GENERIC_CLIENT
|
||||
#include "mesh/generic_client.h"
|
||||
|
||||
/* Generic Client Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_generic_client_cb_to_app(esp_ble_mesh_generic_client_cb_event_t event,
|
||||
esp_ble_mesh_generic_client_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_generic_client_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_generic_client_cb_t)btc_profile_cb_get(BTC_PID_GENERIC_CLIENT);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
btc_ble_mesh_generic_client_args_t *dst = (btc_ble_mesh_generic_client_args_t *)p_dest;
|
||||
btc_ble_mesh_generic_client_args_t *src = (btc_ble_mesh_generic_client_args_t *)p_src;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE: {
|
||||
dst->generic_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->generic_client_get_state.params) {
|
||||
memcpy(dst->generic_client_get_state.params, src->generic_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->generic_client_get_state.get_state) {
|
||||
dst->generic_client_get_state.get_state = (esp_ble_mesh_generic_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_generic_client_get_state_t));
|
||||
if (dst->generic_client_get_state.get_state) {
|
||||
memcpy(dst->generic_client_get_state.get_state, src->generic_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_generic_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE: {
|
||||
dst->generic_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->generic_client_set_state.set_state = (esp_ble_mesh_generic_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_generic_client_set_state_t));
|
||||
if (dst->generic_client_set_state.params && dst->generic_client_set_state.set_state) {
|
||||
memcpy(dst->generic_client_set_state.params, src->generic_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->generic_client_set_state.set_state, src->generic_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_generic_client_set_state_t));
|
||||
|
||||
switch (src->generic_client_set_state.params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
if (src->generic_client_set_state.set_state->user_property_set.property_value) {
|
||||
length = src->generic_client_set_state.set_state->user_property_set.property_value->len;
|
||||
dst->generic_client_set_state.set_state->user_property_set.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!dst->generic_client_set_state.set_state->user_property_set.property_value) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->generic_client_set_state.set_state->user_property_set.property_value,
|
||||
src->generic_client_set_state.set_state->user_property_set.property_value->data,
|
||||
src->generic_client_set_state.set_state->user_property_set.property_value->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
||||
if (src->generic_client_set_state.set_state->admin_property_set.property_value) {
|
||||
length = src->generic_client_set_state.set_state->admin_property_set.property_value->len;
|
||||
dst->generic_client_set_state.set_state->admin_property_set.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!dst->generic_client_set_state.set_state->admin_property_set.property_value) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->generic_client_set_state.set_state->admin_property_set.property_value,
|
||||
src->generic_client_set_state.set_state->admin_property_set.property_value->data,
|
||||
src->generic_client_set_state.set_state->admin_property_set.property_value->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BT_DBG("%s, Unknown act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_generic_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_generic_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE:
|
||||
if (arg->generic_client_get_state.params) {
|
||||
bt_mesh_free(arg->generic_client_get_state.params);
|
||||
}
|
||||
if (arg->generic_client_get_state.get_state) {
|
||||
bt_mesh_free(arg->generic_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE:
|
||||
if (arg->generic_client_set_state.set_state) {
|
||||
if (arg->generic_client_set_state.params) {
|
||||
switch (arg->generic_client_set_state.params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
bt_mesh_free_buf(arg->generic_client_set_state.set_state->user_property_set.property_value);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
||||
bt_mesh_free_buf(arg->generic_client_set_state.set_state->admin_property_set.property_value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
bt_mesh_free(arg->generic_client_set_state.set_state);
|
||||
}
|
||||
if (arg->generic_client_set_state.params) {
|
||||
bt_mesh_free(arg->generic_client_set_state.params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_generic_client_cb_param_t *p_dest_data = (esp_ble_mesh_generic_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_generic_client_cb_param_t *p_src_data = (esp_ble_mesh_generic_client_cb_param_t *)p_src;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_PUBLISH_EVT:
|
||||
if (p_src_data->params) {
|
||||
switch (p_src_data->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS:
|
||||
if (p_src_data->status_cb.user_properties_status.property_ids) {
|
||||
length = p_src_data->status_cb.user_properties_status.property_ids->len;
|
||||
p_dest_data->status_cb.user_properties_status.property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.user_properties_status.property_ids) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.user_properties_status.property_ids,
|
||||
p_src_data->status_cb.user_properties_status.property_ids->data,
|
||||
p_src_data->status_cb.user_properties_status.property_ids->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS:
|
||||
if (p_src_data->status_cb.user_property_status.property_value) {
|
||||
length = p_src_data->status_cb.user_property_status.property_value->len;
|
||||
p_dest_data->status_cb.user_property_status.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.user_property_status.property_value) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.user_property_status.property_value,
|
||||
p_src_data->status_cb.user_property_status.property_value->data,
|
||||
p_src_data->status_cb.user_property_status.property_value->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS:
|
||||
if (p_src_data->status_cb.admin_properties_status.property_ids) {
|
||||
length = p_src_data->status_cb.admin_properties_status.property_ids->len;
|
||||
p_dest_data->status_cb.admin_properties_status.property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.admin_properties_status.property_ids) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.admin_properties_status.property_ids,
|
||||
p_src_data->status_cb.admin_properties_status.property_ids->data,
|
||||
p_src_data->status_cb.admin_properties_status.property_ids->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS:
|
||||
if (p_src_data->status_cb.admin_property_status.property_value) {
|
||||
length = p_src_data->status_cb.admin_property_status.property_value->len;
|
||||
p_dest_data->status_cb.admin_property_status.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.admin_property_status.property_value) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.admin_property_status.property_value,
|
||||
p_src_data->status_cb.admin_property_status.property_value->data,
|
||||
p_src_data->status_cb.admin_property_status.property_value->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTIES_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTIES_STATUS:
|
||||
if (p_src_data->status_cb.manufacturer_properties_status.property_ids) {
|
||||
length = p_src_data->status_cb.manufacturer_properties_status.property_ids->len;
|
||||
p_dest_data->status_cb.manufacturer_properties_status.property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.manufacturer_properties_status.property_ids) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.manufacturer_properties_status.property_ids,
|
||||
p_src_data->status_cb.manufacturer_properties_status.property_ids->data,
|
||||
p_src_data->status_cb.manufacturer_properties_status.property_ids->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_STATUS:
|
||||
if (p_src_data->status_cb.manufacturer_property_status.property_value) {
|
||||
length = p_src_data->status_cb.manufacturer_property_status.property_value->len;
|
||||
p_dest_data->status_cb.manufacturer_property_status.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.manufacturer_property_status.property_value) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.manufacturer_property_status.property_value,
|
||||
p_src_data->status_cb.manufacturer_property_status.property_value->data,
|
||||
p_src_data->status_cb.manufacturer_property_status.property_value->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS:
|
||||
if (p_src_data->status_cb.client_properties_status.property_ids) {
|
||||
length = p_src_data->status_cb.client_properties_status.property_ids->len;
|
||||
p_dest_data->status_cb.client_properties_status.property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.client_properties_status.property_ids) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.client_properties_status.property_ids,
|
||||
p_src_data->status_cb.client_properties_status.property_ids->data,
|
||||
p_src_data->status_cb.client_properties_status.property_ids->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_generic_client_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_generic_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_generic_client_cb_param_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_PUBLISH_EVT:
|
||||
if (arg->params) {
|
||||
switch (arg->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.user_properties_status.property_ids);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.user_property_status.property_value);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.admin_properties_status.property_ids);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.admin_property_status.property_value);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTIES_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTIES_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.manufacturer_properties_status.property_ids);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.manufacturer_property_status.property_value);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.client_properties_status.property_ids);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_generic_client_callback(esp_ble_mesh_generic_client_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_GENERIC_CLIENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GENERIC_CLIENT;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_generic_client_cb_param_t),
|
||||
btc_ble_mesh_generic_client_copy_req_data, btc_ble_mesh_generic_client_free_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_generic_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_generic_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx || len > sizeof(cb_params.status_cb)) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_GENERIC_CLIENT_GET_STATE:
|
||||
act = ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_GENERIC_CLIENT_SET_STATE:
|
||||
act = ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH:
|
||||
act = ESP_BLE_MESH_GENERIC_CLIENT_PUBLISH_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT:
|
||||
act = ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
BT_ERR("Unknown Generic client event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
params.opcode = opcode;
|
||||
params.model = (esp_ble_mesh_model_t *)model;
|
||||
params.ctx.net_idx = ctx->net_idx;
|
||||
params.ctx.app_idx = ctx->app_idx;
|
||||
params.ctx.addr = ctx->addr;
|
||||
params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
params.ctx.recv_op = ctx->recv_op;
|
||||
params.ctx.recv_dst = ctx->recv_dst;
|
||||
params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
cb_params.error_code = 0;
|
||||
cb_params.params = ¶ms;
|
||||
|
||||
if (val && len) {
|
||||
memcpy(&cb_params.status_cb, val, len);
|
||||
}
|
||||
|
||||
btc_ble_mesh_generic_client_callback(&cb_params, act);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_generic_client_publish_callback(uint32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_generic_client_cb_evt_to_btc(opcode, BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH,
|
||||
model, ctx, buf->data, buf->len);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_generic_client_cb_param_t cb = {0};
|
||||
btc_ble_mesh_generic_client_args_t *arg = NULL;
|
||||
bt_mesh_client_common_param_t param = {0};
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_generic_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE:
|
||||
btc_ble_mesh_set_client_common_param(arg->generic_client_get_state.params, ¶m, false);
|
||||
|
||||
cb.params = arg->generic_client_get_state.params;
|
||||
cb.error_code = bt_mesh_generic_client_get_state(¶m, arg->generic_client_get_state.get_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_generic_client_callback(&cb, ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE:
|
||||
btc_ble_mesh_set_client_common_param(arg->generic_client_set_state.params, ¶m, false);
|
||||
|
||||
cb.params = arg->generic_client_set_state.params;
|
||||
cb.error_code = bt_mesh_generic_client_set_state(¶m, arg->generic_client_set_state.set_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_generic_client_callback(&cb, ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
btc_ble_mesh_generic_client_arg_deep_free(msg);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_generic_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_generic_client_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_GENERIC_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_generic_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_generic_client_free_req_data(msg);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_GENERIC_CLIENT */
|
||||
|
||||
#if CONFIG_BLE_MESH_GENERIC_SERVER
|
||||
|
||||
/* Generic Server Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_generic_server_cb_to_app(esp_ble_mesh_generic_server_cb_event_t event,
|
||||
esp_ble_mesh_generic_server_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_generic_server_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_generic_server_cb_t)btc_profile_cb_get(BTC_PID_GENERIC_SERVER);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_generic_server_cb_param_t *p_dest_data = (esp_ble_mesh_generic_server_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_generic_server_cb_param_t *p_src_data = (esp_ble_mesh_generic_server_cb_param_t *)p_src;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_GENERIC_SERVER_STATE_CHANGE_EVT:
|
||||
switch (p_src_data->ctx.recv_op) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK:
|
||||
if (p_src_data->value.state_change.user_property_set.value) {
|
||||
length = p_src_data->value.state_change.user_property_set.value->len;
|
||||
p_dest_data->value.state_change.user_property_set.value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.user_property_set.value == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.user_property_set.value,
|
||||
p_src_data->value.state_change.user_property_set.value->data,
|
||||
p_src_data->value.state_change.user_property_set.value->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK:
|
||||
if (p_src_data->value.state_change.admin_property_set.value) {
|
||||
length = p_src_data->value.state_change.admin_property_set.value->len;
|
||||
p_dest_data->value.state_change.admin_property_set.value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.admin_property_set.value == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.admin_property_set.value,
|
||||
p_src_data->value.state_change.admin_property_set.value->data,
|
||||
p_src_data->value.state_change.admin_property_set.value->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT:
|
||||
switch (p_src_data->ctx.recv_op) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK:
|
||||
if (p_src_data->value.set.user_property.property_value) {
|
||||
length = p_src_data->value.set.user_property.property_value->len;
|
||||
p_dest_data->value.set.user_property.property_value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.set.user_property.property_value == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.user_property.property_value,
|
||||
p_src_data->value.set.user_property.property_value->data,
|
||||
p_src_data->value.set.user_property.property_value->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK:
|
||||
if (p_src_data->value.set.admin_property.property_value) {
|
||||
length = p_src_data->value.set.admin_property.property_value->len;
|
||||
p_dest_data->value.set.admin_property.property_value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.set.admin_property.property_value == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.admin_property.property_value,
|
||||
p_src_data->value.set.admin_property.property_value->data,
|
||||
p_src_data->value.set.admin_property.property_value->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_generic_server_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_generic_server_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_generic_server_cb_param_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_GENERIC_SERVER_STATE_CHANGE_EVT:
|
||||
switch (arg->ctx.recv_op) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK:
|
||||
bt_mesh_free_buf(arg->value.state_change.user_property_set.value);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK:
|
||||
bt_mesh_free_buf(arg->value.state_change.admin_property_set.value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT:
|
||||
switch (arg->ctx.recv_op) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK:
|
||||
bt_mesh_free_buf(arg->value.set.user_property.property_value);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK:
|
||||
bt_mesh_free_buf(arg->value.set.admin_property.property_value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_generic_server_callback(esp_ble_mesh_generic_server_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_GENERIC_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GENERIC_SERVER;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_generic_server_cb_param_t),
|
||||
btc_ble_mesh_generic_server_copy_req_data, btc_ble_mesh_generic_server_free_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_generic_server_cb_evt_to_btc(uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_generic_server_cb_param_t cb_params = {0};
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (model == NULL || ctx == NULL || len > sizeof(cb_params.value)) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_GENERIC_SERVER_STATE_CHANGE:
|
||||
act = ESP_BLE_MESH_GENERIC_SERVER_STATE_CHANGE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_GENERIC_SERVER_RECV_GET_MSG:
|
||||
act = ESP_BLE_MESH_GENERIC_SERVER_RECV_GET_MSG_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_GENERIC_SERVER_RECV_SET_MSG:
|
||||
act = ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
BT_ERR("Unknown Generic Server event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
cb_params.model = (esp_ble_mesh_model_t *)model;
|
||||
cb_params.ctx.net_idx = ctx->net_idx;
|
||||
cb_params.ctx.app_idx = ctx->app_idx;
|
||||
cb_params.ctx.addr = ctx->addr;
|
||||
cb_params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
cb_params.ctx.recv_op = ctx->recv_op;
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
cb_params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
cb_params.ctx.send_ttl = ctx->send_ttl;
|
||||
cb_params.ctx.recv_cred = ctx->recv_cred;
|
||||
|
||||
if (val && len) {
|
||||
memcpy(&cb_params.value, val, len);
|
||||
}
|
||||
|
||||
btc_ble_mesh_generic_server_callback(&cb_params, act);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_generic_server_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_generic_server_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_generic_server_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_GENERIC_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_generic_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_generic_server_free_req_data(msg);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_GENERIC_SERVER */
|
||||
@@ -0,0 +1,608 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc_ble_mesh_model_common.h"
|
||||
#include "btc_ble_mesh_health_model.h"
|
||||
#include "esp_ble_mesh_health_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_HEALTH_CLI
|
||||
#include "mesh/health_cli.h"
|
||||
|
||||
/* Health Client Model related functions */
|
||||
|
||||
static inline void btc_ble_mesh_health_client_cb_to_app(esp_ble_mesh_health_client_cb_event_t event,
|
||||
esp_ble_mesh_health_client_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_health_client_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_health_client_cb_t)btc_profile_cb_get(BTC_PID_HEALTH_CLIENT);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
btc_ble_mesh_health_client_args_t *dst = (btc_ble_mesh_health_client_args_t *)p_dest;
|
||||
btc_ble_mesh_health_client_args_t *src = (btc_ble_mesh_health_client_args_t *)p_src;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE: {
|
||||
dst->health_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->health_client_get_state.params) {
|
||||
memcpy(dst->health_client_get_state.params, src->health_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->health_client_get_state.get_state) {
|
||||
dst->health_client_get_state.get_state = (esp_ble_mesh_health_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_health_client_get_state_t));
|
||||
if (dst->health_client_get_state.get_state) {
|
||||
memcpy(dst->health_client_get_state.get_state, src->health_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_health_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE: {
|
||||
dst->health_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->health_client_set_state.set_state = (esp_ble_mesh_health_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_health_client_set_state_t));
|
||||
if (dst->health_client_set_state.params && dst->health_client_set_state.set_state) {
|
||||
memcpy(dst->health_client_set_state.params, src->health_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->health_client_set_state.set_state, src->health_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_health_client_set_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BT_DBG("%s, Unknown act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_health_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_health_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE:
|
||||
if (arg->health_client_get_state.params) {
|
||||
bt_mesh_free(arg->health_client_get_state.params);
|
||||
}
|
||||
if (arg->health_client_get_state.get_state) {
|
||||
bt_mesh_free(arg->health_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE:
|
||||
if (arg->health_client_set_state.params) {
|
||||
bt_mesh_free(arg->health_client_set_state.params);
|
||||
}
|
||||
if (arg->health_client_set_state.set_state) {
|
||||
bt_mesh_free(arg->health_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_health_client_cb_param_t *p_dest_data = (esp_ble_mesh_health_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_health_client_cb_param_t *p_src_data = (esp_ble_mesh_health_client_cb_param_t *)p_src;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_PUBLISH_EVT:
|
||||
if (p_src_data->params) {
|
||||
switch (p_src_data->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_CURRENT_STATUS:
|
||||
if (p_src_data->status_cb.current_status.fault_array) {
|
||||
length = p_src_data->status_cb.current_status.fault_array->len;
|
||||
p_dest_data->status_cb.current_status.fault_array = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.current_status.fault_array) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.current_status.fault_array,
|
||||
p_src_data->status_cb.current_status.fault_array->data,
|
||||
p_src_data->status_cb.current_status.fault_array->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR:
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST:
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_STATUS:
|
||||
if (p_src_data->status_cb.fault_status.fault_array) {
|
||||
length = p_src_data->status_cb.fault_status.fault_array->len;
|
||||
p_dest_data->status_cb.fault_status.fault_array = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.fault_status.fault_array) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.fault_status.fault_array,
|
||||
p_src_data->status_cb.fault_status.fault_array->data,
|
||||
p_src_data->status_cb.fault_status.fault_array->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_health_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_health_client_cb_param_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_PUBLISH_EVT:
|
||||
if (arg->params) {
|
||||
switch (arg->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_CURRENT_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.current_status.fault_array);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR:
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST:
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.fault_status.fault_array);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_client_callback(esp_ble_mesh_health_client_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_HEALTH_CLIENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_HEALTH_CLIENT;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_health_client_cb_param_t),
|
||||
btc_ble_mesh_health_client_copy_req_data, btc_ble_mesh_health_client_free_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_health_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, uint16_t len)
|
||||
{
|
||||
esp_ble_mesh_health_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx || len > sizeof(cb_params.status_cb)) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_HEALTH_CLIENT_GET_STATE:
|
||||
act = ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_HEALTH_CLIENT_SET_STATE:
|
||||
act = ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH:
|
||||
act = ESP_BLE_MESH_HEALTH_CLIENT_PUBLISH_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT:
|
||||
act = ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
BT_ERR("Unknown Health client event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
params.opcode = opcode;
|
||||
params.model = (esp_ble_mesh_model_t *)model;
|
||||
params.ctx.net_idx = ctx->net_idx;
|
||||
params.ctx.app_idx = ctx->app_idx;
|
||||
params.ctx.addr = ctx->addr;
|
||||
params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
params.ctx.recv_op = ctx->recv_op;
|
||||
params.ctx.recv_dst = ctx->recv_dst;
|
||||
params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
cb_params.error_code = 0;
|
||||
cb_params.params = ¶ms;
|
||||
|
||||
if (val && len) {
|
||||
memcpy(&cb_params.status_cb, val, len);
|
||||
}
|
||||
|
||||
btc_ble_mesh_health_client_callback(&cb_params, act);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_publish_callback(uint32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_health_client_cb_evt_to_btc(opcode, BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH,
|
||||
model, ctx, buf->data, buf->len);
|
||||
}
|
||||
|
||||
static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_health_client_get_state_t *get)
|
||||
{
|
||||
bt_mesh_client_common_param_t param = {0};
|
||||
|
||||
if (params == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (params->opcode == ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET && get == NULL) {
|
||||
BT_ERR("Invalid Health Get");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
btc_ble_mesh_set_client_common_param(params, ¶m, false);
|
||||
|
||||
switch (param.opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_ATTENTION_GET:
|
||||
return bt_mesh_health_attention_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_GET:
|
||||
return bt_mesh_health_period_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET:
|
||||
return bt_mesh_health_fault_get(¶m, get->fault_get.company_id);
|
||||
default:
|
||||
BT_ERR("Invalid Health Get opcode 0x%04x", param.opcode);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
static int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_health_client_set_state_t *set)
|
||||
{
|
||||
bt_mesh_client_common_param_t param = {0};
|
||||
|
||||
if (params == NULL || set == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
btc_ble_mesh_set_client_common_param(params, ¶m, false);
|
||||
|
||||
switch (param.opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET:
|
||||
return bt_mesh_health_attention_set(¶m, set->attention_set.attention, true);
|
||||
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET_UNACK:
|
||||
return bt_mesh_health_attention_set(¶m, set->attention_set.attention, false);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET:
|
||||
return bt_mesh_health_period_set(¶m, set->period_set.fast_period_divisor, true);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET_UNACK:
|
||||
return bt_mesh_health_period_set(¶m, set->period_set.fast_period_divisor, false);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST:
|
||||
return bt_mesh_health_fault_test(¶m, set->fault_test.company_id, set->fault_test.test_id, true);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST_UNACK:
|
||||
return bt_mesh_health_fault_test(¶m, set->fault_test.company_id, set->fault_test.test_id, false);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR:
|
||||
return bt_mesh_health_fault_clear(¶m, set->fault_clear.company_id, true);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR_UNACK:
|
||||
return bt_mesh_health_fault_clear(¶m, set->fault_clear.company_id, false);
|
||||
default:
|
||||
BT_ERR("Invalid Health Set opcode 0x%04x", param.opcode);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_health_client_args_t *arg = NULL;
|
||||
esp_ble_mesh_health_client_cb_param_t cb = {0};
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_health_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE: {
|
||||
cb.params = arg->health_client_get_state.params;
|
||||
cb.error_code = btc_ble_mesh_health_client_get_state(arg->health_client_get_state.params,
|
||||
arg->health_client_get_state.get_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_health_client_callback(&cb, ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE: {
|
||||
cb.params = arg->health_client_set_state.params;
|
||||
cb.error_code = btc_ble_mesh_health_client_set_state(arg->health_client_set_state.params,
|
||||
arg->health_client_set_state.set_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_health_client_callback(&cb, ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
btc_ble_mesh_health_client_arg_deep_free(msg);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_health_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_health_client_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_HEALTH_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_health_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_health_client_free_req_data(msg);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_HEALTH_CLI */
|
||||
|
||||
#if CONFIG_BLE_MESH_HEALTH_SRV
|
||||
#include "mesh/health_srv.h"
|
||||
|
||||
/* Health Server Model related functions */
|
||||
|
||||
static inline void btc_ble_mesh_health_server_cb_to_app(esp_ble_mesh_health_server_cb_event_t event,
|
||||
esp_ble_mesh_health_server_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_health_server_cb_t)btc_profile_cb_get(BTC_PID_HEALTH_SERVER);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_server_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMP_EVT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_server_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMP_EVT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_server_callback(esp_ble_mesh_health_server_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_HEALTH_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_HEALTH_SERVER;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_health_server_cb_param_t),
|
||||
btc_ble_mesh_health_server_copy_req_data, btc_ble_mesh_health_server_free_req_data);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_server_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t param = {0};
|
||||
btc_ble_mesh_health_server_args_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_health_server_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE:
|
||||
param.fault_update_comp.element = arg->health_fault_update.element;
|
||||
param.fault_update_comp.error_code =
|
||||
bt_mesh_fault_update((struct bt_mesh_elem *)arg->health_fault_update.element);
|
||||
btc_ble_mesh_health_server_callback(¶m, ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMP_EVT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
btc_ble_mesh_health_server_arg_deep_free(msg);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_health_server_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_HEALTH_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_health_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_health_server_free_req_data(msg);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_server_fault_clear(struct bt_mesh_model *model, uint16_t company_id)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t param = {0};
|
||||
|
||||
param.fault_clear.model = (esp_ble_mesh_model_t *)model;
|
||||
param.fault_clear.company_id = company_id;
|
||||
|
||||
btc_ble_mesh_health_server_callback(¶m, ESP_BLE_MESH_HEALTH_SERVER_FAULT_CLEAR_EVT);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_server_fault_test(struct bt_mesh_model *model,
|
||||
uint8_t test_id, uint16_t company_id)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t param = {0};
|
||||
|
||||
param.fault_test.model = (esp_ble_mesh_model_t *)model;
|
||||
param.fault_test.test_id = test_id;
|
||||
param.fault_test.company_id = company_id;
|
||||
|
||||
btc_ble_mesh_health_server_callback(¶m, ESP_BLE_MESH_HEALTH_SERVER_FAULT_TEST_EVT);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_server_attention_on(struct bt_mesh_model *model, uint8_t time)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t param = {0};
|
||||
|
||||
param.attention_on.model = (esp_ble_mesh_model_t *)model;
|
||||
param.attention_on.time = time;
|
||||
|
||||
btc_ble_mesh_health_server_callback(¶m, ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_ON_EVT);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_server_attention_off(struct bt_mesh_model *model)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t param = {0};
|
||||
|
||||
param.attention_off.model = (esp_ble_mesh_model_t *)model;
|
||||
|
||||
btc_ble_mesh_health_server_callback(¶m, ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_OFF_EVT);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_HEALTH_SRV */
|
||||
@@ -0,0 +1,545 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc_ble_mesh_model_common.h"
|
||||
#include "btc_ble_mesh_lighting_model.h"
|
||||
#include "esp_ble_mesh_lighting_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_LIGHTING_CLIENT
|
||||
#include "mesh/lighting_client.h"
|
||||
|
||||
/* Lighting Client Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_lighting_client_cb_to_app(esp_ble_mesh_light_client_cb_event_t event,
|
||||
esp_ble_mesh_light_client_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_light_client_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_light_client_cb_t)btc_profile_cb_get(BTC_PID_LIGHTING_CLIENT);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
btc_ble_mesh_lighting_client_args_t *dst = (btc_ble_mesh_lighting_client_args_t *)p_dest;
|
||||
btc_ble_mesh_lighting_client_args_t *src = (btc_ble_mesh_lighting_client_args_t *)p_src;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE: {
|
||||
dst->light_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->light_client_get_state.params) {
|
||||
memcpy(dst->light_client_get_state.params, src->light_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->light_client_get_state.get_state) {
|
||||
dst->light_client_get_state.get_state = (esp_ble_mesh_light_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_light_client_get_state_t));
|
||||
if (dst->light_client_get_state.get_state) {
|
||||
memcpy(dst->light_client_get_state.get_state, src->light_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_light_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE: {
|
||||
dst->light_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->light_client_set_state.set_state = (esp_ble_mesh_light_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_light_client_set_state_t));
|
||||
if (dst->light_client_set_state.params && dst->light_client_set_state.set_state) {
|
||||
memcpy(dst->light_client_set_state.params, src->light_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->light_client_set_state.set_state, src->light_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_light_client_set_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BT_DBG("%s, Unknown act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_lighting_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_lighting_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_lighting_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE:
|
||||
if (arg->light_client_get_state.params) {
|
||||
bt_mesh_free(arg->light_client_get_state.params);
|
||||
}
|
||||
if (arg->light_client_get_state.get_state) {
|
||||
bt_mesh_free(arg->light_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE:
|
||||
if (arg->light_client_set_state.params) {
|
||||
bt_mesh_free(arg->light_client_set_state.params);
|
||||
}
|
||||
if (arg->light_client_set_state.set_state) {
|
||||
bt_mesh_free(arg->light_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_lighting_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_light_client_cb_param_t *p_dest_data = (esp_ble_mesh_light_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_light_client_cb_param_t *p_src_data = (esp_ble_mesh_light_client_cb_param_t *)p_src;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_PUBLISH_EVT:
|
||||
if (p_src_data->params) {
|
||||
switch (p_src_data->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS:
|
||||
if (p_src_data->status_cb.lc_property_status.property_value) {
|
||||
length = p_src_data->status_cb.lc_property_status.property_value->len;
|
||||
p_dest_data->status_cb.lc_property_status.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.lc_property_status.property_value) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.lc_property_status.property_value,
|
||||
p_src_data->status_cb.lc_property_status.property_value->data,
|
||||
p_src_data->status_cb.lc_property_status.property_value->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_lighting_client_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_light_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_light_client_cb_param_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_PUBLISH_EVT:
|
||||
if (arg->params) {
|
||||
switch (arg->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.lc_property_status.property_value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_lighting_client_callback(esp_ble_mesh_light_client_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_LIGHTING_CLIENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_LIGHTING_CLIENT;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_light_client_cb_param_t),
|
||||
btc_ble_mesh_lighting_client_copy_req_data, btc_ble_mesh_lighting_client_free_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_lighting_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_light_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx || len > sizeof(cb_params.status_cb)) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_CLIENT_GET_STATE:
|
||||
act = ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_CLIENT_SET_STATE:
|
||||
act = ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH:
|
||||
act = ESP_BLE_MESH_LIGHT_CLIENT_PUBLISH_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT:
|
||||
act = ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
BT_ERR("Unknown Lighting client event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
params.opcode = opcode;
|
||||
params.model = (esp_ble_mesh_model_t *)model;
|
||||
params.ctx.net_idx = ctx->net_idx;
|
||||
params.ctx.app_idx = ctx->app_idx;
|
||||
params.ctx.addr = ctx->addr;
|
||||
params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
params.ctx.recv_op = ctx->recv_op;
|
||||
params.ctx.recv_dst = ctx->recv_dst;
|
||||
params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
cb_params.error_code = 0;
|
||||
cb_params.params = ¶ms;
|
||||
|
||||
if (val && len) {
|
||||
memcpy(&cb_params.status_cb, val, len);
|
||||
}
|
||||
|
||||
btc_ble_mesh_lighting_client_callback(&cb_params, act);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_lighting_client_publish_callback(uint32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_lighting_client_cb_evt_to_btc(opcode, BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH,
|
||||
model, ctx, buf->data, buf->len);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_lighting_client_args_t *arg = NULL;
|
||||
esp_ble_mesh_light_client_cb_param_t cb = {0};
|
||||
bt_mesh_client_common_param_t param = {0};
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_lighting_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE:
|
||||
btc_ble_mesh_set_client_common_param(arg->light_client_get_state.params, ¶m, false);
|
||||
|
||||
cb.params = arg->light_client_get_state.params;
|
||||
cb.error_code = bt_mesh_light_client_get_state(¶m, arg->light_client_get_state.get_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_lighting_client_callback(&cb, ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE:
|
||||
btc_ble_mesh_set_client_common_param(arg->light_client_set_state.params, ¶m, false);
|
||||
|
||||
cb.params = arg->light_client_set_state.params;
|
||||
cb.error_code = bt_mesh_light_client_set_state(¶m, arg->light_client_set_state.set_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_lighting_client_callback(&cb, ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
btc_ble_mesh_lighting_client_arg_deep_free(msg);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_light_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_light_client_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_LIGHT_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_lighting_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_lighting_client_free_req_data(msg);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_LIGHTING_CLIENT */
|
||||
|
||||
#if CONFIG_BLE_MESH_LIGHTING_SERVER
|
||||
|
||||
/* Lighting Server Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_lighting_server_cb_to_app(esp_ble_mesh_lighting_server_cb_event_t event,
|
||||
esp_ble_mesh_lighting_server_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_lighting_server_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_lighting_server_cb_t)btc_profile_cb_get(BTC_PID_LIGHTING_SERVER);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_lighting_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_lighting_server_cb_param_t *p_dest_data = (esp_ble_mesh_lighting_server_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_lighting_server_cb_param_t *p_src_data = (esp_ble_mesh_lighting_server_cb_param_t *)p_src;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_LIGHTING_SERVER_STATE_CHANGE_EVT:
|
||||
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET ||
|
||||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK) {
|
||||
if (p_src_data->value.state_change.lc_property_set.property_value) {
|
||||
length = p_src_data->value.state_change.lc_property_set.property_value->len;
|
||||
p_dest_data->value.state_change.lc_property_set.property_value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.lc_property_set.property_value == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.lc_property_set.property_value,
|
||||
p_src_data->value.state_change.lc_property_set.property_value->data,
|
||||
p_src_data->value.state_change.lc_property_set.property_value->len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_LIGHTING_SERVER_RECV_SET_MSG_EVT:
|
||||
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET ||
|
||||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK) {
|
||||
if (p_src_data->value.set.lc_property.property_value) {
|
||||
length = p_src_data->value.set.lc_property.property_value->len;
|
||||
p_dest_data->value.set.lc_property.property_value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.set.lc_property.property_value == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.lc_property.property_value,
|
||||
p_src_data->value.set.lc_property.property_value->data,
|
||||
p_src_data->value.set.lc_property.property_value->len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_LIGHTING_SERVER_RECV_STATUS_MSG_EVT:
|
||||
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_STATUS) {
|
||||
if (p_src_data->value.status.sensor_status.data) {
|
||||
length = p_src_data->value.status.sensor_status.data->len;
|
||||
p_dest_data->value.status.sensor_status.data = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.status.sensor_status.data == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.status.sensor_status.data,
|
||||
p_src_data->value.status.sensor_status.data->data,
|
||||
p_src_data->value.status.sensor_status.data->len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_lighting_server_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_lighting_server_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_lighting_server_cb_param_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_LIGHTING_SERVER_STATE_CHANGE_EVT:
|
||||
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET ||
|
||||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK) {
|
||||
bt_mesh_free_buf(arg->value.state_change.lc_property_set.property_value);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_LIGHTING_SERVER_RECV_SET_MSG_EVT:
|
||||
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET ||
|
||||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK) {
|
||||
bt_mesh_free_buf(arg->value.set.lc_property.property_value);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_LIGHTING_SERVER_RECV_STATUS_MSG_EVT:
|
||||
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_STATUS) {
|
||||
bt_mesh_free_buf(arg->value.status.sensor_status.data);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_lighting_server_callback(esp_ble_mesh_lighting_server_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_LIGHTING_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_LIGHTING_SERVER;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_lighting_server_cb_param_t),
|
||||
btc_ble_mesh_lighting_server_copy_req_data, btc_ble_mesh_lighting_server_free_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_lighting_server_cb_evt_to_btc(uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_lighting_server_cb_param_t cb_params = {0};
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (model == NULL || ctx == NULL || len > sizeof(cb_params.value)) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE:
|
||||
act = ESP_BLE_MESH_LIGHTING_SERVER_STATE_CHANGE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_GET_MSG:
|
||||
act = ESP_BLE_MESH_LIGHTING_SERVER_RECV_GET_MSG_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG:
|
||||
act = ESP_BLE_MESH_LIGHTING_SERVER_RECV_SET_MSG_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_STATUS_MSG:
|
||||
act = ESP_BLE_MESH_LIGHTING_SERVER_RECV_STATUS_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
BT_ERR("Unknown Lighting server event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
cb_params.model = (esp_ble_mesh_model_t *)model;
|
||||
cb_params.ctx.net_idx = ctx->net_idx;
|
||||
cb_params.ctx.app_idx = ctx->app_idx;
|
||||
cb_params.ctx.addr = ctx->addr;
|
||||
cb_params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
cb_params.ctx.recv_op = ctx->recv_op;
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
cb_params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
cb_params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
if (val && len) {
|
||||
memcpy(&cb_params.value, val, len);
|
||||
}
|
||||
|
||||
btc_ble_mesh_lighting_server_callback(&cb_params, act);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_lighting_server_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_lighting_server_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_lighting_server_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_LIGHTING_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_lighting_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_lighting_server_free_req_data(msg);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_LIGHTING_SERVER */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,862 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc_ble_mesh_model_common.h"
|
||||
#include "btc_ble_mesh_sensor_model.h"
|
||||
#include "esp_ble_mesh_sensor_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_SENSOR_CLI
|
||||
#include "mesh/sensor_client.h"
|
||||
|
||||
/* Sensor Client Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_sensor_client_cb_to_app(esp_ble_mesh_sensor_client_cb_event_t event,
|
||||
esp_ble_mesh_sensor_client_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_sensor_client_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_sensor_client_cb_t)btc_profile_cb_get(BTC_PID_SENSOR_CLIENT);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
btc_ble_mesh_sensor_client_args_t *dst = (btc_ble_mesh_sensor_client_args_t *)p_dest;
|
||||
btc_ble_mesh_sensor_client_args_t *src = (btc_ble_mesh_sensor_client_args_t *)p_src;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE: {
|
||||
dst->sensor_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->sensor_client_get_state.get_state = (esp_ble_mesh_sensor_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_sensor_client_get_state_t));
|
||||
if (dst->sensor_client_get_state.params && dst->sensor_client_get_state.get_state) {
|
||||
memcpy(dst->sensor_client_get_state.params, src->sensor_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->sensor_client_get_state.get_state, src->sensor_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_sensor_client_get_state_t));
|
||||
|
||||
switch (src->sensor_client_get_state.params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET:
|
||||
if (src->sensor_client_get_state.get_state->column_get.raw_value_x) {
|
||||
length = src->sensor_client_get_state.get_state->column_get.raw_value_x->len;
|
||||
dst->sensor_client_get_state.get_state->column_get.raw_value_x = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_get_state.get_state->column_get.raw_value_x) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_get_state.get_state->column_get.raw_value_x,
|
||||
src->sensor_client_get_state.get_state->column_get.raw_value_x->data,
|
||||
src->sensor_client_get_state.get_state->column_get.raw_value_x->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET:
|
||||
if (src->sensor_client_get_state.get_state->series_get.raw_value_x1) {
|
||||
length = src->sensor_client_get_state.get_state->series_get.raw_value_x1->len;
|
||||
dst->sensor_client_get_state.get_state->series_get.raw_value_x1 = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_get_state.get_state->series_get.raw_value_x1) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_get_state.get_state->series_get.raw_value_x1,
|
||||
src->sensor_client_get_state.get_state->series_get.raw_value_x1->data,
|
||||
src->sensor_client_get_state.get_state->series_get.raw_value_x1->len);
|
||||
}
|
||||
if (src->sensor_client_get_state.get_state->series_get.raw_value_x2) {
|
||||
length = src->sensor_client_get_state.get_state->series_get.raw_value_x2->len;
|
||||
dst->sensor_client_get_state.get_state->series_get.raw_value_x2 = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_get_state.get_state->series_get.raw_value_x2) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_get_state.get_state->series_get.raw_value_x2,
|
||||
src->sensor_client_get_state.get_state->series_get.raw_value_x2->data,
|
||||
src->sensor_client_get_state.get_state->series_get.raw_value_x2->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE: {
|
||||
dst->sensor_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->sensor_client_set_state.set_state = (esp_ble_mesh_sensor_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_sensor_client_set_state_t));
|
||||
if (dst->sensor_client_set_state.params && dst->sensor_client_set_state.set_state) {
|
||||
memcpy(dst->sensor_client_set_state.params, src->sensor_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->sensor_client_set_state.set_state, src->sensor_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_sensor_client_set_state_t));
|
||||
|
||||
switch (src->sensor_client_set_state.params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET:
|
||||
if (src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down) {
|
||||
length = src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down->len;
|
||||
dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down,
|
||||
src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down->data,
|
||||
src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down->len);
|
||||
}
|
||||
if (src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up) {
|
||||
length = src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up->len;
|
||||
dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up,
|
||||
src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up->data,
|
||||
src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up->len);
|
||||
}
|
||||
if (src->sensor_client_set_state.set_state->cadence_set.fast_cadence_low) {
|
||||
length = src->sensor_client_set_state.set_state->cadence_set.fast_cadence_low->len;
|
||||
dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_low = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_low) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_low,
|
||||
src->sensor_client_set_state.set_state->cadence_set.fast_cadence_low->data,
|
||||
src->sensor_client_set_state.set_state->cadence_set.fast_cadence_low->len);
|
||||
}
|
||||
if (src->sensor_client_set_state.set_state->cadence_set.fast_cadence_high) {
|
||||
length = src->sensor_client_set_state.set_state->cadence_set.fast_cadence_high->len;
|
||||
dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_high = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_high) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_high,
|
||||
src->sensor_client_set_state.set_state->cadence_set.fast_cadence_high->data,
|
||||
src->sensor_client_set_state.set_state->cadence_set.fast_cadence_high->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET:
|
||||
if (src->sensor_client_set_state.set_state->setting_set.sensor_setting_raw) {
|
||||
length = src->sensor_client_set_state.set_state->setting_set.sensor_setting_raw->len;
|
||||
dst->sensor_client_set_state.set_state->setting_set.sensor_setting_raw = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->setting_set.sensor_setting_raw) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->setting_set.sensor_setting_raw,
|
||||
src->sensor_client_set_state.set_state->setting_set.sensor_setting_raw->data,
|
||||
src->sensor_client_set_state.set_state->setting_set.sensor_setting_raw->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BT_DBG("%s, Unknown act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_sensor_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_sensor_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE:
|
||||
if (arg->sensor_client_get_state.get_state) {
|
||||
if (arg->sensor_client_get_state.params) {
|
||||
switch (arg->sensor_client_get_state.params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET:
|
||||
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->column_get.raw_value_x);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET:
|
||||
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->series_get.raw_value_x1);
|
||||
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->series_get.raw_value_x2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
bt_mesh_free(arg->sensor_client_get_state.get_state);
|
||||
}
|
||||
if (arg->sensor_client_get_state.params) {
|
||||
bt_mesh_free(arg->sensor_client_get_state.params);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE:
|
||||
if (arg->sensor_client_set_state.set_state) {
|
||||
if (arg->sensor_client_set_state.params) {
|
||||
switch (arg->sensor_client_set_state.params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET:
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down);
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up);
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.fast_cadence_low);
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.fast_cadence_high);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET:
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->setting_set.sensor_setting_raw);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
bt_mesh_free(arg->sensor_client_set_state.set_state);
|
||||
}
|
||||
if (arg->sensor_client_set_state.params) {
|
||||
bt_mesh_free(arg->sensor_client_set_state.params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_sensor_client_cb_param_t *p_dest_data = (esp_ble_mesh_sensor_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_sensor_client_cb_param_t *p_src_data = (esp_ble_mesh_sensor_client_cb_param_t *)p_src;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_PUBLISH_EVT:
|
||||
if (p_src_data->params) {
|
||||
switch (p_src_data->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS:
|
||||
if (p_src_data->status_cb.descriptor_status.descriptor) {
|
||||
length = p_src_data->status_cb.descriptor_status.descriptor->len;
|
||||
p_dest_data->status_cb.descriptor_status.descriptor = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.descriptor_status.descriptor) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.descriptor_status.descriptor,
|
||||
p_src_data->status_cb.descriptor_status.descriptor->data,
|
||||
p_src_data->status_cb.descriptor_status.descriptor->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_STATUS:
|
||||
if (p_src_data->status_cb.cadence_status.sensor_cadence_value) {
|
||||
length = p_src_data->status_cb.cadence_status.sensor_cadence_value->len;
|
||||
p_dest_data->status_cb.cadence_status.sensor_cadence_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.cadence_status.sensor_cadence_value) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.cadence_status.sensor_cadence_value,
|
||||
p_src_data->status_cb.cadence_status.sensor_cadence_value->data,
|
||||
p_src_data->status_cb.cadence_status.sensor_cadence_value->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTINGS_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS:
|
||||
if (p_src_data->status_cb.settings_status.sensor_setting_property_ids) {
|
||||
length = p_src_data->status_cb.settings_status.sensor_setting_property_ids->len;
|
||||
p_dest_data->status_cb.settings_status.sensor_setting_property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.settings_status.sensor_setting_property_ids) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.settings_status.sensor_setting_property_ids,
|
||||
p_src_data->status_cb.settings_status.sensor_setting_property_ids->data,
|
||||
p_src_data->status_cb.settings_status.sensor_setting_property_ids->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_STATUS:
|
||||
if (p_src_data->status_cb.setting_status.sensor_setting_raw) {
|
||||
length = p_src_data->status_cb.setting_status.sensor_setting_raw->len;
|
||||
p_dest_data->status_cb.setting_status.sensor_setting_raw = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.setting_status.sensor_setting_raw) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.setting_status.sensor_setting_raw,
|
||||
p_src_data->status_cb.setting_status.sensor_setting_raw->data,
|
||||
p_src_data->status_cb.setting_status.sensor_setting_raw->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_STATUS:
|
||||
if (p_src_data->status_cb.sensor_status.marshalled_sensor_data) {
|
||||
length = p_src_data->status_cb.sensor_status.marshalled_sensor_data->len;
|
||||
p_dest_data->status_cb.sensor_status.marshalled_sensor_data = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.sensor_status.marshalled_sensor_data) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.sensor_status.marshalled_sensor_data,
|
||||
p_src_data->status_cb.sensor_status.marshalled_sensor_data->data,
|
||||
p_src_data->status_cb.sensor_status.marshalled_sensor_data->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS:
|
||||
if (p_src_data->status_cb.column_status.sensor_column_value) {
|
||||
length = p_src_data->status_cb.column_status.sensor_column_value->len;
|
||||
p_dest_data->status_cb.column_status.sensor_column_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.column_status.sensor_column_value) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.column_status.sensor_column_value,
|
||||
p_src_data->status_cb.column_status.sensor_column_value->data,
|
||||
p_src_data->status_cb.column_status.sensor_column_value->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS:
|
||||
if (p_src_data->status_cb.series_status.sensor_series_value) {
|
||||
length = p_src_data->status_cb.series_status.sensor_series_value->len;
|
||||
p_dest_data->status_cb.series_status.sensor_series_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.series_status.sensor_series_value) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.series_status.sensor_series_value,
|
||||
p_src_data->status_cb.series_status.sensor_series_value->data,
|
||||
p_src_data->status_cb.series_status.sensor_series_value->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_sensor_client_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_sensor_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_sensor_client_cb_param_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_PUBLISH_EVT:
|
||||
if (arg->params) {
|
||||
switch (arg->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.descriptor_status.descriptor);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.cadence_status.sensor_cadence_value);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTINGS_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.settings_status.sensor_setting_property_ids);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.setting_status.sensor_setting_raw);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.sensor_status.marshalled_sensor_data);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.column_status.sensor_column_value);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.series_status.sensor_series_value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_sensor_client_callback(esp_ble_mesh_sensor_client_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_SENSOR_CLIENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_SENSOR_CLIENT;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_sensor_client_cb_param_t),
|
||||
btc_ble_mesh_sensor_client_copy_req_data, btc_ble_mesh_sensor_client_free_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_sensor_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_sensor_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx || len > sizeof(cb_params.status_cb)) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_SENSOR_CLIENT_GET_STATE:
|
||||
act = ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_SENSOR_CLIENT_SET_STATE:
|
||||
act = ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH:
|
||||
act = ESP_BLE_MESH_SENSOR_CLIENT_PUBLISH_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT:
|
||||
act = ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
BT_ERR("Unknown Sensor client event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
params.opcode = opcode;
|
||||
params.model = (esp_ble_mesh_model_t *)model;
|
||||
params.ctx.net_idx = ctx->net_idx;
|
||||
params.ctx.app_idx = ctx->app_idx;
|
||||
params.ctx.addr = ctx->addr;
|
||||
params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
params.ctx.recv_op = ctx->recv_op;
|
||||
params.ctx.recv_dst = ctx->recv_dst;
|
||||
params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
cb_params.error_code = 0;
|
||||
cb_params.params = ¶ms;
|
||||
|
||||
if (val && len) {
|
||||
memcpy(&cb_params.status_cb, val, len);
|
||||
}
|
||||
|
||||
btc_ble_mesh_sensor_client_callback(&cb_params, act);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_sensor_client_publish_callback(uint32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_sensor_client_cb_evt_to_btc(opcode, BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH,
|
||||
model, ctx, buf->data, buf->len);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_sensor_client_cb_param_t cb = {0};
|
||||
btc_ble_mesh_sensor_client_args_t *arg = NULL;
|
||||
bt_mesh_client_common_param_t param = {0};
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_sensor_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE:
|
||||
btc_ble_mesh_set_client_common_param(arg->sensor_client_get_state.params, ¶m, false);
|
||||
|
||||
cb.params = arg->sensor_client_get_state.params;
|
||||
cb.error_code = bt_mesh_sensor_client_get_state(¶m, arg->sensor_client_get_state.get_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_sensor_client_callback(&cb, ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE:
|
||||
btc_ble_mesh_set_client_common_param(arg->sensor_client_set_state.params, ¶m, false);
|
||||
|
||||
cb.params = arg->sensor_client_set_state.params;
|
||||
cb.error_code = bt_mesh_sensor_client_set_state(¶m, arg->sensor_client_set_state.set_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_sensor_client_callback(&cb, ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
btc_ble_mesh_sensor_client_arg_deep_free(msg);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_sensor_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_sensor_client_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_SENSOR_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_sensor_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_sensor_client_free_req_data(msg);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_SENSOR_CLI */
|
||||
|
||||
#if CONFIG_BLE_MESH_SENSOR_SERVER
|
||||
|
||||
/* Sensor Server Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_sensor_server_cb_to_app(esp_ble_mesh_sensor_server_cb_event_t event,
|
||||
esp_ble_mesh_sensor_server_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_sensor_server_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_sensor_server_cb_t)btc_profile_cb_get(BTC_PID_SENSOR_SERVER);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_sensor_server_cb_param_t *p_dest_data = (esp_ble_mesh_sensor_server_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_sensor_server_cb_param_t *p_src_data = (esp_ble_mesh_sensor_server_cb_param_t *)p_src;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_SENSOR_SERVER_STATE_CHANGE_EVT:
|
||||
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET ||
|
||||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK) {
|
||||
if (p_src_data->value.state_change.sensor_cadence_set.trigger_delta_down) {
|
||||
length = p_src_data->value.state_change.sensor_cadence_set.trigger_delta_down->len;
|
||||
p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_down = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_down == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_down,
|
||||
p_src_data->value.state_change.sensor_cadence_set.trigger_delta_down->data,
|
||||
p_src_data->value.state_change.sensor_cadence_set.trigger_delta_down->len);
|
||||
}
|
||||
if (p_src_data->value.state_change.sensor_cadence_set.trigger_delta_up) {
|
||||
length = p_src_data->value.state_change.sensor_cadence_set.trigger_delta_up->len;
|
||||
p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_up = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_up == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_up,
|
||||
p_src_data->value.state_change.sensor_cadence_set.trigger_delta_up->data,
|
||||
p_src_data->value.state_change.sensor_cadence_set.trigger_delta_up->len);
|
||||
}
|
||||
if (p_src_data->value.state_change.sensor_cadence_set.fast_cadence_low) {
|
||||
length = p_src_data->value.state_change.sensor_cadence_set.fast_cadence_low->len;
|
||||
p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_low = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_low == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_low,
|
||||
p_src_data->value.state_change.sensor_cadence_set.fast_cadence_low->data,
|
||||
p_src_data->value.state_change.sensor_cadence_set.fast_cadence_low->len);
|
||||
}
|
||||
if (p_src_data->value.state_change.sensor_cadence_set.fast_cadence_high) {
|
||||
length = p_src_data->value.state_change.sensor_cadence_set.fast_cadence_high->len;
|
||||
p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_high = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_high == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_high,
|
||||
p_src_data->value.state_change.sensor_cadence_set.fast_cadence_high->data,
|
||||
p_src_data->value.state_change.sensor_cadence_set.fast_cadence_high->len);
|
||||
}
|
||||
} else if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET ||
|
||||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK) {
|
||||
if (p_src_data->value.state_change.sensor_setting_set.setting_value) {
|
||||
length = p_src_data->value.state_change.sensor_setting_set.setting_value->len;
|
||||
p_dest_data->value.state_change.sensor_setting_set.setting_value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.sensor_setting_set.setting_value == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_setting_set.setting_value,
|
||||
p_src_data->value.state_change.sensor_setting_set.setting_value->data,
|
||||
p_src_data->value.state_change.sensor_setting_set.setting_value->len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_SENSOR_SERVER_RECV_GET_MSG_EVT:
|
||||
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET) {
|
||||
if (p_src_data->value.get.sensor_column.raw_value_x) {
|
||||
length = p_src_data->value.get.sensor_column.raw_value_x->len;
|
||||
p_dest_data->value.get.sensor_column.raw_value_x = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.get.sensor_column.raw_value_x == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.get.sensor_column.raw_value_x,
|
||||
p_src_data->value.get.sensor_column.raw_value_x->data,
|
||||
p_src_data->value.get.sensor_column.raw_value_x->len);
|
||||
}
|
||||
} else if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET) {
|
||||
if (p_src_data->value.get.sensor_series.raw_value) {
|
||||
length = p_src_data->value.get.sensor_series.raw_value->len;
|
||||
p_dest_data->value.get.sensor_series.raw_value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.get.sensor_series.raw_value == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.get.sensor_series.raw_value,
|
||||
p_src_data->value.get.sensor_series.raw_value->data,
|
||||
p_src_data->value.get.sensor_series.raw_value->len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT:
|
||||
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET ||
|
||||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK) {
|
||||
if (p_src_data->value.set.sensor_cadence.cadence) {
|
||||
length = p_src_data->value.set.sensor_cadence.cadence->len;
|
||||
p_dest_data->value.set.sensor_cadence.cadence = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.set.sensor_cadence.cadence == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.sensor_cadence.cadence,
|
||||
p_src_data->value.set.sensor_cadence.cadence->data,
|
||||
p_src_data->value.set.sensor_cadence.cadence->len);
|
||||
}
|
||||
} else if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET ||
|
||||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK) {
|
||||
if (p_src_data->value.set.sensor_setting.setting_raw) {
|
||||
length = p_src_data->value.set.sensor_setting.setting_raw->len;
|
||||
p_dest_data->value.set.sensor_setting.setting_raw = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.set.sensor_setting.setting_raw == NULL) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.sensor_setting.setting_raw,
|
||||
p_src_data->value.set.sensor_setting.setting_raw->data,
|
||||
p_src_data->value.set.sensor_setting.setting_raw->len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_sensor_server_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_sensor_server_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_sensor_server_cb_param_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_SENSOR_SERVER_STATE_CHANGE_EVT:
|
||||
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET ||
|
||||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK) {
|
||||
bt_mesh_free_buf(arg->value.state_change.sensor_cadence_set.trigger_delta_down);
|
||||
bt_mesh_free_buf(arg->value.state_change.sensor_cadence_set.trigger_delta_up);
|
||||
bt_mesh_free_buf(arg->value.state_change.sensor_cadence_set.fast_cadence_low);
|
||||
bt_mesh_free_buf(arg->value.state_change.sensor_cadence_set.fast_cadence_high);
|
||||
} else if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET ||
|
||||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK) {
|
||||
bt_mesh_free_buf(arg->value.state_change.sensor_setting_set.setting_value);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_SENSOR_SERVER_RECV_GET_MSG_EVT:
|
||||
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET) {
|
||||
bt_mesh_free_buf(arg->value.get.sensor_column.raw_value_x);
|
||||
} else if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET) {
|
||||
bt_mesh_free_buf(arg->value.get.sensor_series.raw_value);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT:
|
||||
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET ||
|
||||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK) {
|
||||
bt_mesh_free_buf(arg->value.set.sensor_cadence.cadence);
|
||||
} else if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET ||
|
||||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK) {
|
||||
bt_mesh_free_buf(arg->value.set.sensor_setting.setting_raw);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_sensor_server_callback(esp_ble_mesh_sensor_server_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_SENSOR_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_SENSOR_SERVER;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_sensor_server_cb_param_t),
|
||||
btc_ble_mesh_sensor_server_copy_req_data, btc_ble_mesh_sensor_server_free_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_sensor_server_cb_evt_to_btc(uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_sensor_server_cb_param_t cb_params = {0};
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (model == NULL || ctx == NULL || len > sizeof(cb_params.value)) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_SENSOR_SERVER_STATE_CHANGE:
|
||||
act = ESP_BLE_MESH_SENSOR_SERVER_STATE_CHANGE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_SENSOR_SERVER_RECV_GET_MSG:
|
||||
act = ESP_BLE_MESH_SENSOR_SERVER_RECV_GET_MSG_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_SENSOR_SERVER_RECV_SET_MSG:
|
||||
act = ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
BT_ERR("Unknown Sensor server event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
cb_params.model = (esp_ble_mesh_model_t *)model;
|
||||
cb_params.ctx.net_idx = ctx->net_idx;
|
||||
cb_params.ctx.app_idx = ctx->app_idx;
|
||||
cb_params.ctx.addr = ctx->addr;
|
||||
cb_params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
cb_params.ctx.recv_op = ctx->recv_op;
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
cb_params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
cb_params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
if (val && len) {
|
||||
memcpy(&cb_params.value, val, len);
|
||||
}
|
||||
|
||||
btc_ble_mesh_sensor_server_callback(&cb_params, act);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_sensor_server_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_sensor_server_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_sensor_server_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_SENSOR_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_sensor_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_sensor_server_free_req_data(msg);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_SENSOR_SERVER */
|
||||
@@ -0,0 +1,446 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc_ble_mesh_model_common.h"
|
||||
#include "btc_ble_mesh_time_scene_model.h"
|
||||
#include "esp_ble_mesh_time_scene_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_TIME_SCENE_CLIENT
|
||||
#include "mesh/time_scene_client.h"
|
||||
|
||||
/* Time and Scenes Client Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_time_scene_client_cb_to_app(esp_ble_mesh_time_scene_client_cb_event_t event,
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_time_scene_client_cb_t)btc_profile_cb_get(BTC_PID_TIME_SCENE_CLIENT);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
btc_ble_mesh_time_scene_client_args_t *dst = (btc_ble_mesh_time_scene_client_args_t *)p_dest;
|
||||
btc_ble_mesh_time_scene_client_args_t *src = (btc_ble_mesh_time_scene_client_args_t *)p_src;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE: {
|
||||
dst->time_scene_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->time_scene_client_get_state.params) {
|
||||
memcpy(dst->time_scene_client_get_state.params, src->time_scene_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->time_scene_client_get_state.get_state) {
|
||||
dst->time_scene_client_get_state.get_state = (esp_ble_mesh_time_scene_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_time_scene_client_get_state_t));
|
||||
if (dst->time_scene_client_get_state.get_state) {
|
||||
memcpy(dst->time_scene_client_get_state.get_state, src->time_scene_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_time_scene_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE: {
|
||||
dst->time_scene_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->time_scene_client_set_state.set_state = (esp_ble_mesh_time_scene_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_time_scene_client_set_state_t));
|
||||
if (dst->time_scene_client_set_state.params && dst->time_scene_client_set_state.set_state) {
|
||||
memcpy(dst->time_scene_client_set_state.params, src->time_scene_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->time_scene_client_set_state.set_state, src->time_scene_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_time_scene_client_set_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BT_DBG("%s, Unknown act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_time_scene_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_time_scene_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_time_scene_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE:
|
||||
if (arg->time_scene_client_get_state.params) {
|
||||
bt_mesh_free(arg->time_scene_client_get_state.params);
|
||||
}
|
||||
if (arg->time_scene_client_get_state.get_state) {
|
||||
bt_mesh_free(arg->time_scene_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE:
|
||||
if (arg->time_scene_client_set_state.params) {
|
||||
bt_mesh_free(arg->time_scene_client_set_state.params);
|
||||
}
|
||||
if (arg->time_scene_client_set_state.set_state) {
|
||||
bt_mesh_free(arg->time_scene_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_time_scene_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *p_dest_data = (esp_ble_mesh_time_scene_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *p_src_data = (esp_ble_mesh_time_scene_client_cb_param_t *)p_src;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_PUBLISH_EVT:
|
||||
if (p_src_data->params) {
|
||||
switch (p_src_data->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_STORE:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_DELETE:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS:
|
||||
if (p_src_data->status_cb.scene_register_status.scenes) {
|
||||
length = p_src_data->status_cb.scene_register_status.scenes->len;
|
||||
p_dest_data->status_cb.scene_register_status.scenes = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.scene_register_status.scenes) {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.scene_register_status.scenes,
|
||||
p_src_data->status_cb.scene_register_status.scenes->data,
|
||||
p_src_data->status_cb.scene_register_status.scenes->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_time_scene_client_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_time_scene_client_cb_param_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_PUBLISH_EVT:
|
||||
if (arg->params) {
|
||||
switch (arg->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_STORE:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_DELETE:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.scene_register_status.scenes);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_time_scene_client_callback(esp_ble_mesh_time_scene_client_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_TIME_SCENE_CLIENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_TIME_SCENE_CLIENT;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_time_scene_client_cb_param_t),
|
||||
btc_ble_mesh_time_scene_client_copy_req_data, btc_ble_mesh_time_scene_client_free_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_time_scene_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx || len > sizeof(cb_params.status_cb)) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_GET_STATE:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_SET_STATE:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_CLIENT_PUBLISH_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_TIMEOUT:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
BT_ERR("Unknown Time Scene client event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
params.opcode = opcode;
|
||||
params.model = (esp_ble_mesh_model_t *)model;
|
||||
params.ctx.net_idx = ctx->net_idx;
|
||||
params.ctx.app_idx = ctx->app_idx;
|
||||
params.ctx.addr = ctx->addr;
|
||||
params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
params.ctx.recv_op = ctx->recv_op;
|
||||
params.ctx.recv_dst = ctx->recv_dst;
|
||||
params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
cb_params.error_code = 0;
|
||||
cb_params.params = ¶ms;
|
||||
|
||||
if (val && len) {
|
||||
memcpy(&cb_params.status_cb, val, len);
|
||||
}
|
||||
|
||||
btc_ble_mesh_time_scene_client_callback(&cb_params, act);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_time_scene_client_publish_callback(uint32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_time_scene_client_cb_evt_to_btc(opcode, BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH,
|
||||
model, ctx, buf->data, buf->len);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_param_t cb = {0};
|
||||
btc_ble_mesh_time_scene_client_args_t *arg = NULL;
|
||||
bt_mesh_client_common_param_t param = {0};
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_time_scene_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE:
|
||||
btc_ble_mesh_set_client_common_param(arg->time_scene_client_get_state.params, ¶m, false);
|
||||
|
||||
cb.params = arg->time_scene_client_get_state.params;
|
||||
cb.error_code = bt_mesh_time_scene_client_get_state(¶m, arg->time_scene_client_get_state.get_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_time_scene_client_callback(&cb, ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE:
|
||||
btc_ble_mesh_set_client_common_param(arg->time_scene_client_set_state.params, ¶m, false);
|
||||
|
||||
cb.params = arg->time_scene_client_set_state.params;
|
||||
cb.error_code = bt_mesh_time_scene_client_set_state(¶m, arg->time_scene_client_set_state.set_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_time_scene_client_callback(&cb, ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
btc_ble_mesh_time_scene_client_arg_deep_free(msg);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_time_scene_client_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_TIME_SCENE_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_time_scene_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_time_scene_client_free_req_data(msg);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_TIME_SCENE_CLIENT */
|
||||
|
||||
#if CONFIG_BLE_MESH_TIME_SCENE_SERVER
|
||||
|
||||
/* Time and Scenes Server Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_time_scene_server_cb_to_app(esp_ble_mesh_time_scene_server_cb_event_t event,
|
||||
esp_ble_mesh_time_scene_server_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_time_scene_server_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_time_scene_server_cb_t)btc_profile_cb_get(BTC_PID_TIME_SCENE_SERVER);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_time_scene_server_callback(esp_ble_mesh_time_scene_server_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_TIME_SCENE_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_TIME_SCENE_SERVER;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_time_scene_server_cb_param_t), NULL, NULL);
|
||||
}
|
||||
|
||||
void bt_mesh_time_scene_server_cb_evt_to_btc(uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_time_scene_server_cb_param_t cb_params = {0};
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (model == NULL || ctx == NULL || len > sizeof(cb_params.value)) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_STATE_CHANGE:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_SERVER_STATE_CHANGE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_GET_MSG:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_GET_MSG_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_SET_MSG:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_SET_MSG_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_STATUS_MSG:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_STATUS_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
BT_ERR("Unknown Time Scene server event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
cb_params.model = (esp_ble_mesh_model_t *)model;
|
||||
cb_params.ctx.net_idx = ctx->net_idx;
|
||||
cb_params.ctx.app_idx = ctx->app_idx;
|
||||
cb_params.ctx.addr = ctx->addr;
|
||||
cb_params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
cb_params.ctx.recv_op = ctx->recv_op;
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
cb_params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
cb_params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
if (val && len) {
|
||||
memcpy(&cb_params.value, val, len);
|
||||
}
|
||||
|
||||
btc_ble_mesh_time_scene_server_callback(&cb_params, act);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_time_scene_server_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_time_scene_server_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_time_scene_server_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_TIME_SCENE_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_time_scene_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_TIME_SCENE_SERVER */
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _BTC_BLE_MESH_BLE_H_
|
||||
#define _BTC_BLE_MESH_BLE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "btc/btc_manage.h"
|
||||
#include "mesh/adapter.h"
|
||||
#include "esp_ble_mesh_ble_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
esp_ble_mesh_ble_adv_param_t param;
|
||||
esp_ble_mesh_ble_adv_data_t data;
|
||||
} start_ble_adv;
|
||||
struct {
|
||||
uint8_t index;
|
||||
} stop_ble_adv;
|
||||
struct {
|
||||
esp_ble_mesh_ble_scan_param_t param;
|
||||
} start_ble_scan;
|
||||
struct {
|
||||
/* RFU */
|
||||
} stop_ble_scan;
|
||||
} btc_ble_mesh_ble_args_t;
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_START_BLE_ADV,
|
||||
BTC_BLE_MESH_ACT_STOP_BLE_ADV,
|
||||
BTC_BLE_MESH_ACT_START_BLE_SCAN,
|
||||
BTC_BLE_MESH_ACT_STOP_BLE_SCAN,
|
||||
} btc_ble_mesh_ble_act_t;
|
||||
|
||||
void bt_mesh_ble_scan_cb_evt_to_btc(const bt_mesh_addr_t *addr,
|
||||
uint8_t adv_type, uint8_t data[],
|
||||
uint16_t length, int8_t rssi);
|
||||
|
||||
void btc_ble_mesh_ble_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_ble_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BTC_BLE_MESH_BLE_H_ */
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _BTC_BLE_MESH_CONFIG_MODEL_H_
|
||||
#define _BTC_BLE_MESH_CONFIG_MODEL_H_
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "esp_ble_mesh_config_model_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_ACT_CONFIG_CLIENT_MAX,
|
||||
} btc_ble_mesh_config_client_act_t;
|
||||
|
||||
typedef union {
|
||||
struct ble_mesh_cfg_client_get_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_cfg_client_get_state_t *get_state;
|
||||
} cfg_client_get_state;
|
||||
struct ble_mesh_cfg_client_set_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_cfg_client_set_state_t *set_state;
|
||||
} cfg_client_set_state;
|
||||
} btc_ble_mesh_config_client_args_t;
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_CONFIG_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_EVT_CONFIG_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH,
|
||||
BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT,
|
||||
BTC_BLE_MESH_EVT_CONFIG_CLIENT_MAX,
|
||||
} btc_ble_mesh_config_client_evt_t;
|
||||
|
||||
void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_ble_mesh_config_client_arg_deep_free(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_config_client_publish_callback(uint32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_config_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len);
|
||||
|
||||
void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg);
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
|
||||
BTC_BLE_MESH_EVT_CONFIG_SERVER_MAX,
|
||||
} btc_ble_mesh_config_server_evt_t;
|
||||
|
||||
void bt_mesh_config_server_cb_evt_to_btc(uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BTC_BLE_MESH_CONFIG_MODEL_H_ */
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _BTC_BLE_MESH_GENERIC_MODEL_H_
|
||||
#define _BTC_BLE_MESH_GENERIC_MODEL_H_
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "esp_ble_mesh_generic_model_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_ACT_GENERIC_CLIENT_MAX,
|
||||
} btc_ble_mesh_generic_client_act_t;
|
||||
|
||||
typedef union {
|
||||
struct ble_mesh_generic_client_get_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_generic_client_get_state_t *get_state;
|
||||
} generic_client_get_state;
|
||||
struct ble_mesh_generic_client_set_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_generic_client_set_state_t *set_state;
|
||||
} generic_client_set_state;
|
||||
} btc_ble_mesh_generic_client_args_t;
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_GENERIC_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_EVT_GENERIC_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH,
|
||||
BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT,
|
||||
BTC_BLE_MESH_EVT_GENERIC_CLIENT_MAX,
|
||||
} btc_ble_mesh_generic_client_evt_t;
|
||||
|
||||
void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_generic_client_publish_callback(uint32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_generic_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len);
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_GENERIC_SERVER_STATE_CHANGE,
|
||||
BTC_BLE_MESH_EVT_GENERIC_SERVER_RECV_GET_MSG,
|
||||
BTC_BLE_MESH_EVT_GENERIC_SERVER_RECV_SET_MSG,
|
||||
BTC_BLE_MESH_EVT_GENERIC_SERVER_MAX,
|
||||
} btc_ble_mesh_generic_server_evt_t;
|
||||
|
||||
void bt_mesh_generic_server_cb_evt_to_btc(uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len);
|
||||
|
||||
void btc_ble_mesh_generic_server_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BTC_BLE_MESH_GENERIC_MODEL_H_ */
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _BTC_BLE_MESH_HEALTH_MODEL_H_
|
||||
#define _BTC_BLE_MESH_HEALTH_MODEL_H_
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "esp_ble_mesh_health_model_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_ACT_HEALTH_CLIENT_MAX,
|
||||
} btc_ble_mesh_health_client_act_t;
|
||||
|
||||
typedef union {
|
||||
struct ble_mesh_health_client_get_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_health_client_get_state_t *get_state;
|
||||
} health_client_get_state;
|
||||
struct ble_mesh_health_client_set_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_health_client_set_state_t *set_state;
|
||||
} health_client_set_state;
|
||||
} btc_ble_mesh_health_client_args_t;
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_HEALTH_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_EVT_HEALTH_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH,
|
||||
BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT,
|
||||
BTC_BLE_MESH_EVT_HEALTH_CLIENT_MAX,
|
||||
} btc_ble_mesh_health_client_evt_t;
|
||||
|
||||
void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_ble_mesh_health_client_arg_deep_free(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_health_publish_callback(uint32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_health_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, uint16_t len);
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE,
|
||||
BTC_BLE_MESH_ACT_HEALTH_SERVER_MAX,
|
||||
} btc_ble_mesh_health_server_act_t;
|
||||
|
||||
typedef union {
|
||||
struct ble_mesh_health_server_fault_update_args {
|
||||
esp_ble_mesh_elem_t *element;
|
||||
} health_fault_update;
|
||||
} btc_ble_mesh_health_server_args_t;
|
||||
|
||||
void btc_ble_mesh_health_server_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_ble_mesh_health_server_fault_clear(struct bt_mesh_model *model, uint16_t company_id);
|
||||
|
||||
void btc_ble_mesh_health_server_fault_test(struct bt_mesh_model *model,
|
||||
uint8_t test_id, uint16_t company_id);
|
||||
|
||||
void btc_ble_mesh_health_server_attention_on(struct bt_mesh_model *model, uint8_t time);
|
||||
|
||||
void btc_ble_mesh_health_server_attention_off(struct bt_mesh_model *model);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BTC_BLE_MESH_HEALTH_MODEL_H_ */
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _BTC_BLE_MESH_LIGHTING_MODEL_H_
|
||||
#define _BTC_BLE_MESH_LIGHTING_MODEL_H_
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "esp_ble_mesh_lighting_model_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_ACT_LIGHTING_CLIENT_MAX,
|
||||
} btc_ble_mesh_lighting_client_act_t;
|
||||
|
||||
typedef union {
|
||||
struct ble_mesh_light_client_get_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_light_client_get_state_t *get_state;
|
||||
} light_client_get_state;
|
||||
struct ble_mesh_light_client_set_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_light_client_set_state_t *set_state;
|
||||
} light_client_set_state;
|
||||
} btc_ble_mesh_lighting_client_args_t;
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_MAX,
|
||||
} btc_ble_mesh_lighting_client_evt_t;
|
||||
|
||||
void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_ble_mesh_lighting_client_arg_deep_free(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_lighting_client_publish_callback(uint32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_lighting_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len);
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_GET_MSG,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_STATUS_MSG,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_SERVER_MAX,
|
||||
} btc_ble_mesh_lighting_server_evt_t;
|
||||
|
||||
void bt_mesh_lighting_server_cb_evt_to_btc(uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len);
|
||||
|
||||
void btc_ble_mesh_lighting_server_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BTC_BLE_MESH_LIGHTING_MODEL_H_ */
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _BTC_BLE_MESH_MODEL_COMMON_H_
|
||||
#define _BTC_BLE_MESH_MODEL_COMMON_H_
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "mesh/access.h"
|
||||
#include "mesh/client_common.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static inline void btc_ble_mesh_set_client_common_param(esp_ble_mesh_client_common_param_t *input,
|
||||
bt_mesh_client_common_param_t *output,
|
||||
bool use_dev_key)
|
||||
{
|
||||
if (input && output) {
|
||||
output->opcode = input->opcode;
|
||||
output->model = (struct bt_mesh_model *)input->model;
|
||||
output->ctx.net_idx = input->ctx.net_idx;
|
||||
output->ctx.app_idx = use_dev_key ? BLE_MESH_KEY_DEV : input->ctx.app_idx;
|
||||
output->ctx.addr = input->ctx.addr;
|
||||
output->ctx.send_szmic = input->ctx.send_szmic;
|
||||
output->ctx.send_ttl = input->ctx.send_ttl;
|
||||
output->ctx.send_cred = input->ctx.send_cred;
|
||||
output->ctx.send_tag = input->ctx.send_tag;
|
||||
output->msg_timeout = input->msg_timeout;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BTC_BLE_MESH_MODEL_COMMON_H_ */
|
||||
@@ -0,0 +1,434 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _BTC_BLE_MESH_PROV_H_
|
||||
#define _BTC_BLE_MESH_PROV_H_
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "mesh/byteorder.h"
|
||||
#include "mesh/config.h"
|
||||
#include "mesh/main.h"
|
||||
#include "fast_prov.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_MESH_INIT = 0,
|
||||
BTC_BLE_MESH_ACT_PROV_ENABLE,
|
||||
BTC_BLE_MESH_ACT_PROV_DISABLE,
|
||||
BTC_BLE_MESH_ACT_NODE_RESET,
|
||||
BTC_BLE_MESH_ACT_SET_OOB_PUB_KEY,
|
||||
BTC_BLE_MESH_ACT_INPUT_NUMBER,
|
||||
BTC_BLE_MESH_ACT_INPUT_STRING,
|
||||
BTC_BLE_MESH_ACT_SET_DEVICE_NAME,
|
||||
BTC_BLE_MESH_ACT_PROXY_IDENTITY_ENABLE,
|
||||
BTC_BLE_MESH_ACT_PRIVATE_PROXY_IDENTITY_ENABLE,
|
||||
BTC_BLE_MESH_ACT_PRIVATE_PROXY_IDENTITY_DISABLE,
|
||||
BTC_BLE_MESH_ACT_PROXY_GATT_ENABLE,
|
||||
BTC_BLE_MESH_ACT_PROXY_GATT_DISABLE,
|
||||
BTC_BLE_MESH_ACT_NODE_ADD_LOCAL_NET_KEY,
|
||||
BTC_BLE_MESH_ACT_NODE_ADD_LOCAL_APP_KEY,
|
||||
BTC_BLE_MESH_ACT_NODE_BIND_APP_KEY_TO_MODEL,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_READ_OOB_PUB_KEY,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_INPUT_STR,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_INPUT_NUM,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_ENABLE,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DISABLE,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DEV_ADD,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_PROV_DEV_WITH_ADDR,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DEV_DEL,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_DEV_UUID_MATCH,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_PROV_DATA_INFO,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_STATIC_OOB_VAL,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_PRIMARY_ELEM_ADDR,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_NODE_NAME,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_ADD_LOCAL_APP_KEY,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_APP_KEY,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_BIND_LOCAL_MOD_APP,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_ADD_LOCAL_NET_KEY,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_NET_KEY,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_STORE_NODE_COMP_DATA,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_NODE_WITH_UUID,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_NODE_WITH_ADDR,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_ENABLE_HEARTBEAT_RECV,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_HEARTBEAT_FILTER_TYPE,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_HEARTBEAT_FILTER_INFO,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DIRECT_ERASE_SETTINGS,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_OPEN_SETTINGS_WITH_INDEX,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_OPEN_SETTINGS_WITH_UID,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_CLOSE_SETTINGS_WITH_INDEX,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_CLOSE_SETTINGS_WITH_UID,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_SETTINGS_WITH_INDEX,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_SETTINGS_WITH_UID,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SEND_PROV_RECORDS_GET,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SEND_PROV_RECORD_REQUEST,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SEND_PROV_INVITE,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SEND_LINK_CLOSE,
|
||||
BTC_BLE_MESH_ACT_SET_FAST_PROV_INFO,
|
||||
BTC_BLE_MESH_ACT_SET_FAST_PROV_ACTION,
|
||||
BTC_BLE_MESH_ACT_LPN_ENABLE,
|
||||
BTC_BLE_MESH_ACT_LPN_DISABLE,
|
||||
BTC_BLE_MESH_ACT_LPN_POLL,
|
||||
BTC_BLE_MESH_ACT_PROXY_CLIENT_CONNECT,
|
||||
BTC_BLE_MESH_ACT_PROXY_CLIENT_DISCONNECT,
|
||||
BTC_BLE_MESH_ACT_PROXY_CLIENT_SET_FILTER_TYPE,
|
||||
BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR,
|
||||
BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR,
|
||||
BTC_BLE_MESH_ACT_PROXY_CLIENT_DIRECTED_PROXY_SET,
|
||||
BTC_BLE_MESH_ACT_PROXY_CLIENT_SEND_SOLIC_PDU,
|
||||
BTC_BLE_MESH_ACT_MODEL_SUBSCRIBE_GROUP_ADDR,
|
||||
BTC_BLE_MESH_ACT_MODEL_UNSUBSCRIBE_GROUP_ADDR,
|
||||
BTC_BLE_MESH_ACT_DEINIT_MESH,
|
||||
} btc_ble_mesh_prov_act_t;
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_MODEL_PUBLISH,
|
||||
BTC_BLE_MESH_ACT_SERVER_MODEL_SEND,
|
||||
BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND,
|
||||
BTC_BLE_MESH_ACT_SERVER_MODEL_UPDATE_STATE,
|
||||
} btc_ble_mesh_model_act_t;
|
||||
|
||||
typedef union {
|
||||
struct ble_mesh_init_args {
|
||||
esp_ble_mesh_prov_t *prov;
|
||||
esp_ble_mesh_comp_t *comp;
|
||||
SemaphoreHandle_t semaphore;
|
||||
} mesh_init;
|
||||
struct ble_mesh_node_prov_enable_args {
|
||||
esp_ble_mesh_prov_bearer_t bearers;
|
||||
} node_prov_enable;
|
||||
struct ble_mesh_node_prov_disable_args {
|
||||
esp_ble_mesh_prov_bearer_t bearers;
|
||||
} node_prov_disable;
|
||||
struct ble_mesh_set_oob_pub_key_args {
|
||||
uint8_t pub_key_x[32];
|
||||
uint8_t pub_key_y[32];
|
||||
uint8_t private_key[32];
|
||||
} set_oob_pub_key;
|
||||
struct ble_mesh_node_input_num_args {
|
||||
uint32_t number;
|
||||
} input_number;
|
||||
struct ble_mesh_node_input_str_args {
|
||||
char string[8];
|
||||
} input_string;
|
||||
struct ble_mesh_set_device_name_args {
|
||||
char name[ESP_BLE_MESH_DEVICE_NAME_MAX_LEN + 1];
|
||||
} set_device_name;
|
||||
struct ble_mesh_node_add_local_net_key_args {
|
||||
uint8_t net_key[16];
|
||||
uint16_t net_idx;
|
||||
} node_add_local_net_key;
|
||||
struct ble_mesh_node_add_local_app_key_args {
|
||||
uint8_t app_key[16];
|
||||
uint16_t net_idx;
|
||||
uint16_t app_idx;
|
||||
} node_add_local_app_key;
|
||||
struct ble_mesh_node_bind_local_mod_app_args {
|
||||
uint16_t element_addr;
|
||||
uint16_t company_id;
|
||||
uint16_t model_id;
|
||||
uint16_t app_idx;
|
||||
} node_local_mod_app_bind;
|
||||
struct ble_mesh_provisioner_read_oob_pub_key_args {
|
||||
uint8_t link_idx;
|
||||
uint8_t pub_key_x[32];
|
||||
uint8_t pub_key_y[32];
|
||||
} provisioner_read_oob_pub_key;
|
||||
struct ble_mesh_provisioner_input_str_args {
|
||||
char string[8];
|
||||
uint8_t link_idx;
|
||||
} provisioner_input_str;
|
||||
struct ble_mesh_provisioner_input_num_args {
|
||||
uint32_t number;
|
||||
uint8_t link_idx;
|
||||
} provisioner_input_num;
|
||||
struct ble_mesh_provisioner_enable_args {
|
||||
esp_ble_mesh_prov_bearer_t bearers;
|
||||
} provisioner_enable;
|
||||
struct ble_mesh_provisioner_disable_args {
|
||||
esp_ble_mesh_prov_bearer_t bearers;
|
||||
} provisioner_disable;
|
||||
struct ble_mesh_provisioner_dev_add_args {
|
||||
esp_ble_mesh_unprov_dev_add_t add_dev;
|
||||
esp_ble_mesh_dev_add_flag_t flags;
|
||||
} provisioner_dev_add;
|
||||
struct ble_mesh_provisioner_prov_dev_with_addr_args {
|
||||
uint8_t uuid[16];
|
||||
esp_ble_mesh_bd_addr_t addr;
|
||||
esp_ble_mesh_addr_type_t addr_type;
|
||||
esp_ble_mesh_prov_bearer_t bearer;
|
||||
uint16_t oob_info;
|
||||
uint16_t unicast_addr;
|
||||
} provisioner_prov_dev_with_addr;
|
||||
struct ble_mesh_provisioner_dev_del_args {
|
||||
esp_ble_mesh_device_delete_t del_dev;
|
||||
} provisioner_dev_del;
|
||||
struct ble_mesh_provisioner_set_dev_uuid_match_args {
|
||||
uint8_t offset;
|
||||
uint8_t match_len;
|
||||
uint8_t match_val[16];
|
||||
bool prov_after_match;
|
||||
} set_dev_uuid_match;
|
||||
struct ble_mesh_provisioner_set_prov_net_idx_args {
|
||||
esp_ble_mesh_prov_data_info_t prov_data;
|
||||
} set_prov_data_info;
|
||||
struct ble_mesh_provisioner_set_static_oob_val_args {
|
||||
uint8_t value[16];
|
||||
uint8_t length;
|
||||
} set_static_oob_val;
|
||||
struct ble_mesh_provisioner_set_primary_elem_addr_args {
|
||||
uint16_t addr;
|
||||
} set_primary_elem_addr;
|
||||
struct ble_mesh_provisioner_set_node_name_args {
|
||||
uint16_t index;
|
||||
char name[ESP_BLE_MESH_NODE_NAME_MAX_LEN + 1];
|
||||
} set_node_name;
|
||||
struct ble_mesh_provisioner_add_local_app_key_args {
|
||||
uint8_t app_key[16];
|
||||
uint16_t net_idx;
|
||||
uint16_t app_idx;
|
||||
} add_local_app_key;
|
||||
struct ble_mesh_provisioner_update_local_app_key_args {
|
||||
uint8_t app_key[16];
|
||||
uint16_t net_idx;
|
||||
uint16_t app_idx;
|
||||
} update_local_app_key;
|
||||
struct ble_mesh_provisioner_bind_local_mod_app_args {
|
||||
uint16_t elem_addr;
|
||||
uint16_t model_id;
|
||||
uint16_t cid;
|
||||
uint16_t app_idx;
|
||||
} local_mod_app_bind;
|
||||
struct ble_mesh_provisioner_add_local_net_key_args {
|
||||
uint8_t net_key[16];
|
||||
uint16_t net_idx;
|
||||
} add_local_net_key;
|
||||
struct ble_mesh_provisioner_update_local_net_key_args {
|
||||
uint8_t net_key[16];
|
||||
uint16_t net_idx;
|
||||
} update_local_net_key;
|
||||
struct ble_mesh_provisioner_store_node_comp_data_args {
|
||||
uint16_t unicast_addr;
|
||||
uint16_t length;
|
||||
uint8_t *data;
|
||||
} store_node_comp_data;
|
||||
struct ble_mesh_provisioner_delete_node_with_uuid_args {
|
||||
uint8_t uuid[16];
|
||||
} delete_node_with_uuid;
|
||||
struct ble_mesh_provisioner_delete_node_with_addr_args {
|
||||
uint16_t unicast_addr;
|
||||
} delete_node_with_addr;
|
||||
struct {
|
||||
bool enable;
|
||||
} enable_heartbeat_recv;
|
||||
struct {
|
||||
uint8_t type;
|
||||
} set_heartbeat_filter_type;
|
||||
struct {
|
||||
uint8_t op;
|
||||
uint16_t hb_src;
|
||||
uint16_t hb_dst;
|
||||
} set_heartbeat_filter_info;
|
||||
struct {
|
||||
uint8_t index;
|
||||
} open_settings_with_index;
|
||||
struct {
|
||||
char uid[ESP_BLE_MESH_SETTINGS_UID_SIZE + 1];
|
||||
} open_settings_with_uid;
|
||||
struct {
|
||||
uint8_t index;
|
||||
bool erase;
|
||||
} close_settings_with_index;
|
||||
struct {
|
||||
char uid[ESP_BLE_MESH_SETTINGS_UID_SIZE + 1];
|
||||
bool erase;
|
||||
} close_settings_with_uid;
|
||||
struct {
|
||||
uint8_t index;
|
||||
} delete_settings_with_index;
|
||||
struct {
|
||||
char uid[ESP_BLE_MESH_SETTINGS_UID_SIZE + 1];
|
||||
} delete_settings_with_uid;
|
||||
struct {
|
||||
uint16_t link_idx;
|
||||
} send_prov_records_get;
|
||||
struct {
|
||||
uint16_t link_idx;
|
||||
uint16_t record_id;
|
||||
uint16_t frag_offset;
|
||||
uint16_t max_size;
|
||||
} send_prov_record_req;
|
||||
struct {
|
||||
uint16_t link_idx;
|
||||
} send_prov_invite;
|
||||
struct {
|
||||
uint16_t link_idx;
|
||||
} send_link_close;
|
||||
struct ble_mesh_set_fast_prov_info_args {
|
||||
uint16_t unicast_min;
|
||||
uint16_t unicast_max;
|
||||
uint16_t net_idx;
|
||||
uint8_t flags;
|
||||
uint32_t iv_index;
|
||||
uint8_t offset;
|
||||
uint8_t match_len;
|
||||
uint8_t match_val[16];
|
||||
} set_fast_prov_info;
|
||||
struct ble_mesh_set_fast_prov_action_args {
|
||||
uint8_t action;
|
||||
} set_fast_prov_action;
|
||||
struct ble_mesh_lpn_enable_args {
|
||||
/* RFU */
|
||||
} lpn_enable;
|
||||
struct ble_mesh_lpn_disable_args {
|
||||
bool force;
|
||||
} lpn_disable;
|
||||
struct ble_mesh_lpn_poll_args {
|
||||
/* RFU */
|
||||
} lpn_poll;
|
||||
struct ble_mesh_proxy_client_connect_args {
|
||||
uint8_t addr[6];
|
||||
uint8_t addr_type;
|
||||
uint16_t net_idx;
|
||||
} proxy_client_connect;
|
||||
struct ble_mesh_proxy_client_disconnect_args {
|
||||
uint8_t conn_handle;
|
||||
} proxy_client_disconnect;
|
||||
struct ble_mesh_proxy_client_set_filter_type_args {
|
||||
uint8_t conn_handle;
|
||||
uint16_t net_idx;
|
||||
uint8_t filter_type;
|
||||
} proxy_client_set_filter_type;
|
||||
struct ble_mesh_proxy_client_add_filter_addr_args {
|
||||
uint8_t conn_handle;
|
||||
uint16_t net_idx;
|
||||
uint16_t addr_num;
|
||||
uint16_t *addr;
|
||||
} proxy_client_add_filter_addr;
|
||||
struct ble_mesh_proxy_client_remove_filter_addr_args {
|
||||
uint8_t conn_handle;
|
||||
uint16_t net_idx;
|
||||
uint16_t addr_num;
|
||||
uint16_t *addr;
|
||||
} proxy_client_remove_filter_addr;
|
||||
struct ble_mesh_proxy_client_directed_proxy_set_args {
|
||||
uint8_t conn_handle;
|
||||
uint16_t net_idx;
|
||||
uint8_t use_directed;
|
||||
} proxy_client_directed_proxy_set;
|
||||
struct {
|
||||
uint16_t net_idx;
|
||||
uint16_t ssrc;
|
||||
uint16_t dst;
|
||||
} proxy_client_send_solic_pdu;
|
||||
struct ble_mesh_model_sub_group_addr_args {
|
||||
uint16_t element_addr;
|
||||
uint16_t company_id;
|
||||
uint16_t model_id;
|
||||
uint16_t group_addr;
|
||||
} model_sub_group_addr;
|
||||
struct ble_mesh_model_unsub_group_addr_args {
|
||||
uint16_t element_addr;
|
||||
uint16_t company_id;
|
||||
uint16_t model_id;
|
||||
uint16_t group_addr;
|
||||
} model_unsub_group_addr;
|
||||
struct ble_mesh_deinit_args {
|
||||
esp_ble_mesh_deinit_param_t param;
|
||||
SemaphoreHandle_t semaphore;
|
||||
} mesh_deinit;
|
||||
} btc_ble_mesh_prov_args_t;
|
||||
|
||||
typedef union {
|
||||
struct ble_mesh_model_publish_args {
|
||||
esp_ble_mesh_model_t *model;
|
||||
uint8_t device_role __attribute__((deprecated));
|
||||
} model_publish;
|
||||
struct ble_mesh_model_send_args {
|
||||
esp_ble_mesh_model_t *model;
|
||||
esp_ble_mesh_msg_ctx_t *ctx;
|
||||
uint32_t opcode;
|
||||
bool need_rsp;
|
||||
uint16_t length;
|
||||
uint8_t *data;
|
||||
uint8_t device_role __attribute__((deprecated));
|
||||
int32_t msg_timeout;
|
||||
} model_send;
|
||||
struct ble_mesh_server_model_update_state_args {
|
||||
esp_ble_mesh_model_t *model;
|
||||
esp_ble_mesh_server_state_type_t type;
|
||||
esp_ble_mesh_server_state_value_t *value;
|
||||
} model_update_state;
|
||||
} btc_ble_mesh_model_args_t;
|
||||
|
||||
void btc_ble_mesh_prov_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_ble_mesh_prov_arg_deep_free(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_model_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_ble_mesh_model_arg_deep_free(btc_msg_t *msg);
|
||||
|
||||
const uint8_t *btc_ble_mesh_node_get_local_net_key(uint16_t net_idx);
|
||||
|
||||
const uint8_t *btc_ble_mesh_node_get_local_app_key(uint16_t app_idx);
|
||||
|
||||
esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_uuid(const uint8_t uuid[16]);
|
||||
|
||||
esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr);
|
||||
|
||||
esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_name(const char *name);
|
||||
|
||||
uint16_t btc_ble_mesh_provisioner_get_prov_node_count(void);
|
||||
|
||||
const esp_ble_mesh_node_t **btc_ble_mesh_provisioner_get_node_table_entry(void);
|
||||
|
||||
int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model);
|
||||
|
||||
int btc_ble_mesh_client_model_deinit(esp_ble_mesh_model_t *model);
|
||||
|
||||
int32_t btc_ble_mesh_model_pub_period_get(esp_ble_mesh_model_t *mod);
|
||||
|
||||
uint16_t btc_ble_mesh_get_primary_addr(void);
|
||||
|
||||
uint16_t *btc_ble_mesh_model_find_group(esp_ble_mesh_model_t *mod, uint16_t addr);
|
||||
|
||||
esp_ble_mesh_elem_t *btc_ble_mesh_elem_find(uint16_t addr);
|
||||
|
||||
uint8_t btc_ble_mesh_elem_count(void);
|
||||
|
||||
esp_ble_mesh_model_t *btc_ble_mesh_model_find_vnd(const esp_ble_mesh_elem_t *elem,
|
||||
uint16_t company, uint16_t id);
|
||||
|
||||
esp_ble_mesh_model_t *btc_ble_mesh_model_find(const esp_ble_mesh_elem_t *elem, uint16_t id);
|
||||
|
||||
const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void);
|
||||
|
||||
const char *btc_ble_mesh_provisioner_get_settings_uid(uint8_t index);
|
||||
|
||||
uint8_t btc_ble_mesh_provisioner_get_settings_index(const char *uid);
|
||||
|
||||
uint8_t btc_ble_mesh_provisioner_get_free_settings_count(void);
|
||||
|
||||
void btc_ble_mesh_model_call_handler(btc_msg_t *msg);
|
||||
void btc_ble_mesh_model_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_prov_call_handler(btc_msg_t *msg);
|
||||
void btc_ble_mesh_prov_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#if CONFIG_BLE_MESH_DF_SRV
|
||||
int btc_ble_mesh_enable_directed_forwarding(uint16_t net_idx, bool directed_forwarding,
|
||||
bool directed_forwarding_relay);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BTC_BLE_MESH_PROV_H_ */
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _BTC_BLE_MESH_SENSOR_MODEL_H_
|
||||
#define _BTC_BLE_MESH_SENSOR_MODEL_H_
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "esp_ble_mesh_sensor_model_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_ACT_SENSOR_CLIENT_MAX,
|
||||
} btc_ble_mesh_sensor_client_act_t;
|
||||
|
||||
typedef union {
|
||||
struct ble_mesh_sensor_client_get_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_sensor_client_get_state_t *get_state;
|
||||
} sensor_client_get_state;
|
||||
struct ble_mesh_sensor_client_set_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_sensor_client_set_state_t *set_state;
|
||||
} sensor_client_set_state;
|
||||
} btc_ble_mesh_sensor_client_args_t;
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_SENSOR_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_EVT_SENSOR_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH,
|
||||
BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT,
|
||||
BTC_BLE_MESH_EVT_SENSOR_CLIENT_MAX,
|
||||
} btc_ble_mesh_sensor_client_evt_t;
|
||||
|
||||
void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_sensor_client_publish_callback(uint32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_sensor_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len);
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_SENSOR_SERVER_STATE_CHANGE,
|
||||
BTC_BLE_MESH_EVT_SENSOR_SERVER_RECV_GET_MSG,
|
||||
BTC_BLE_MESH_EVT_SENSOR_SERVER_RECV_SET_MSG,
|
||||
BTC_BLE_MESH_EVT_SENSOR_SERVER_MAX,
|
||||
} btc_ble_mesh_sensor_server_evt_t;
|
||||
|
||||
void bt_mesh_sensor_server_cb_evt_to_btc(uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len);
|
||||
|
||||
void btc_ble_mesh_sensor_server_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BTC_BLE_MESH_SENSOR_MODEL_H_ */
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _BTC_BLE_MESH_TIME_SCENE_MODEL_H_
|
||||
#define _BTC_BLE_MESH_TIME_SCENE_MODEL_H_
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "esp_ble_mesh_time_scene_model_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_MAX,
|
||||
} btc_ble_mesh_time_scene_client_act_t;
|
||||
|
||||
typedef union {
|
||||
struct ble_mesh_time_scene_client_get_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_time_scene_client_get_state_t *get_state;
|
||||
} time_scene_client_get_state;
|
||||
struct ble_mesh_time_scene_client_set_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_time_scene_client_set_state_t *set_state;
|
||||
} time_scene_client_set_state;
|
||||
} btc_ble_mesh_time_scene_client_args_t;
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_TIMEOUT,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_MAX,
|
||||
} btc_ble_mesh_time_scene_client_evt_t;
|
||||
|
||||
void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_ble_mesh_time_scene_client_arg_deep_free(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_time_scene_client_publish_callback(uint32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_time_scene_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len);
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_STATE_CHANGE,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_GET_MSG,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_SET_MSG,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_STATUS_MSG,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_MAX,
|
||||
} btc_ble_mesh_time_scene_server_evt_t;
|
||||
|
||||
void bt_mesh_time_scene_server_cb_evt_to_btc(uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len);
|
||||
|
||||
void btc_ble_mesh_time_scene_server_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BTC_BLE_MESH_TIME_SCENE_MODEL_H_ */
|
||||
Reference in New Issue
Block a user