Merge branch 'bugfix/ble_mesh_client_msg_optimize' into 'master'

Bugfix/ble mesh client msg optimize

See merge request espressif/esp-idf!9366
This commit is contained in:
Island 2020-08-07 11:04:21 +08:00
commit 0b9e303e93
21 changed files with 608 additions and 1312 deletions

View File

@ -20,8 +20,6 @@
#include "cfg_cli.h"
#include "esp_ble_mesh_config_model_api.h"
extern s32_t config_msg_timeout;
/* 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,
@ -317,7 +315,6 @@ void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
{
esp_ble_mesh_cfg_client_cb_param_t cb_params = {0};
esp_ble_mesh_client_common_param_t params = {0};
size_t length = 0U;
uint8_t act = 0U;
if (!model || !ctx) {
@ -358,8 +355,7 @@ void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
cb_params.params = &params;
if (val && len) {
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
memcpy(&cb_params.status_cb, val, length);
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
}
btc_ble_mesh_config_client_callback(&cb_params, act);
@ -383,7 +379,7 @@ void btc_ble_mesh_config_client_publish_callback(u32_t opcode, struct bt_mesh_mo
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)
{
struct bt_mesh_msg_ctx ctx = {0};
bt_mesh_client_common_param_t param = {0};
if (params == NULL) {
BT_ERR("%s, Invalid parameter", __func__);
@ -410,63 +406,65 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param
break;
}
ctx.net_idx = params->ctx.net_idx;
ctx.app_idx = BLE_MESH_KEY_DEV;
ctx.addr = params->ctx.addr;
ctx.send_rel = params->ctx.send_rel;
ctx.send_ttl = params->ctx.send_ttl;
param.opcode = params->opcode;
param.model = (struct bt_mesh_model *)params->model;
param.ctx.net_idx = params->ctx.net_idx;
param.ctx.app_idx = BLE_MESH_KEY_DEV;
param.ctx.addr = params->ctx.addr;
param.ctx.send_rel = params->ctx.send_rel;
param.ctx.send_ttl = params->ctx.send_ttl;
param.msg_timeout = params->msg_timeout;
param.msg_role = params->msg_role;
config_msg_timeout = params->msg_timeout;
switch (params->opcode) {
switch (param.opcode) {
case ESP_BLE_MESH_MODEL_OP_BEACON_GET:
return bt_mesh_cfg_beacon_get(&ctx);
return bt_mesh_cfg_beacon_get(&param);
case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_GET:
return bt_mesh_cfg_ttl_get(&ctx);
return bt_mesh_cfg_ttl_get(&param);
case ESP_BLE_MESH_MODEL_OP_FRIEND_GET:
return bt_mesh_cfg_friend_get(&ctx);
return bt_mesh_cfg_friend_get(&param);
case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_GET:
return bt_mesh_cfg_gatt_proxy_get(&ctx);
return bt_mesh_cfg_gatt_proxy_get(&param);
case ESP_BLE_MESH_MODEL_OP_RELAY_GET:
return bt_mesh_cfg_relay_get(&ctx);
return bt_mesh_cfg_relay_get(&param);
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET:
return bt_mesh_cfg_mod_pub_get(&ctx, get->model_pub_get.element_addr,
return bt_mesh_cfg_mod_pub_get(&param, 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(&ctx);
return bt_mesh_cfg_hb_pub_get(&param);
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_GET:
return bt_mesh_cfg_hb_sub_get(&ctx);
return bt_mesh_cfg_hb_sub_get(&param);
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
return bt_mesh_cfg_comp_data_get(&ctx, get->comp_data_get.page);
return bt_mesh_cfg_comp_data_get(&param, get->comp_data_get.page);
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
return bt_mesh_cfg_mod_sub_get(&ctx, get->sig_model_sub_get.element_addr,
return bt_mesh_cfg_mod_sub_get(&param, 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(&ctx, get->vnd_model_sub_get.element_addr,
return bt_mesh_cfg_mod_sub_get_vnd(&param, 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(&ctx);
return bt_mesh_cfg_net_key_get(&param);
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
return bt_mesh_cfg_app_key_get(&ctx, get->app_key_get.net_idx);
return bt_mesh_cfg_app_key_get(&param, get->app_key_get.net_idx);
case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET:
return bt_mesh_cfg_node_identity_get(&ctx, get->node_identity_get.net_idx);
return bt_mesh_cfg_node_identity_get(&param, get->node_identity_get.net_idx);
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET:
return bt_mesh_cfg_mod_app_get(&ctx, get->sig_model_app_get.element_addr,
return bt_mesh_cfg_mod_app_get(&param, 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(&ctx, get->vnd_model_app_get.element_addr,
return bt_mesh_cfg_mod_app_get_vnd(&param, 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(&ctx, get->kr_phase_get.net_idx);
return bt_mesh_cfg_kr_phase_get(&param, get->kr_phase_get.net_idx);
case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET:
return bt_mesh_cfg_lpn_timeout_get(&ctx, get->lpn_pollto_get.lpn_addr);
return bt_mesh_cfg_lpn_timeout_get(&param, get->lpn_pollto_get.lpn_addr);
case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_GET:
return bt_mesh_cfg_net_transmit_get(&ctx);
return bt_mesh_cfg_net_transmit_get(&param);
default:
BT_ERR("Invalid Configuration Get opcode 0x%04x", params->opcode);
BT_ERR("Invalid Configuration Get opcode 0x%04x", param.opcode);
return -EINVAL;
}
@ -476,7 +474,7 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param
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)
{
struct bt_mesh_msg_ctx ctx = {0};
bt_mesh_client_common_param_t param = {0};
if (params == NULL) {
BT_ERR("%s, Invalid parameter", __func__);
@ -488,35 +486,37 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param
return -EINVAL;
}
ctx.net_idx = params->ctx.net_idx;
ctx.app_idx = BLE_MESH_KEY_DEV;
ctx.addr = params->ctx.addr;
ctx.send_rel = params->ctx.send_rel;
ctx.send_ttl = params->ctx.send_ttl;
param.opcode = params->opcode;
param.model = (struct bt_mesh_model *)params->model;
param.ctx.net_idx = params->ctx.net_idx;
param.ctx.app_idx = BLE_MESH_KEY_DEV;
param.ctx.addr = params->ctx.addr;
param.ctx.send_rel = params->ctx.send_rel;
param.ctx.send_ttl = params->ctx.send_ttl;
param.msg_timeout = params->msg_timeout;
param.msg_role = params->msg_role;
config_msg_timeout = params->msg_timeout;
switch (params->opcode) {
switch (param.opcode) {
case ESP_BLE_MESH_MODEL_OP_BEACON_SET:
return bt_mesh_cfg_beacon_set(&ctx, set->beacon_set.beacon);
return bt_mesh_cfg_beacon_set(&param, set->beacon_set.beacon);
case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_SET:
return bt_mesh_cfg_ttl_set(&ctx, set->default_ttl_set.ttl);
return bt_mesh_cfg_ttl_set(&param, set->default_ttl_set.ttl);
case ESP_BLE_MESH_MODEL_OP_FRIEND_SET:
return bt_mesh_cfg_friend_set(&ctx, set->friend_set.friend_state);
return bt_mesh_cfg_friend_set(&param, set->friend_set.friend_state);
case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_SET:
return bt_mesh_cfg_gatt_proxy_set(&ctx, set->gatt_proxy_set.gatt_proxy);
return bt_mesh_cfg_gatt_proxy_set(&param, set->gatt_proxy_set.gatt_proxy);
case ESP_BLE_MESH_MODEL_OP_RELAY_SET:
return bt_mesh_cfg_relay_set(&ctx, set->relay_set.relay,
return bt_mesh_cfg_relay_set(&param, 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(&ctx, set->net_key_add.net_idx,
return bt_mesh_cfg_net_key_add(&param, 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(&ctx, set->app_key_add.net_idx,
return bt_mesh_cfg_app_key_add(&param, 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(&ctx, set->model_app_bind.element_addr,
return bt_mesh_cfg_mod_app_bind(&param, 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);
@ -529,46 +529,46 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param
.period = set->model_pub_set.publish_period,
.transmit = set->model_pub_set.publish_retransmit,
};
return bt_mesh_cfg_mod_pub_set(&ctx, set->model_pub_set.element_addr,
return bt_mesh_cfg_mod_pub_set(&param, 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(&ctx, set->model_sub_add.element_addr,
return bt_mesh_cfg_mod_sub_add(&param, 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(&ctx, set->model_sub_delete.element_addr,
return bt_mesh_cfg_mod_sub_del(&param, 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(&ctx, set->model_sub_overwrite.element_addr,
return bt_mesh_cfg_mod_sub_overwrite(&param, 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(&ctx, set->model_sub_va_add.element_addr,
return bt_mesh_cfg_mod_sub_va_add(&param, 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(&ctx, set->model_sub_va_overwrite.element_addr,
return bt_mesh_cfg_mod_sub_va_overwrite(&param, 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(&ctx, set->model_sub_va_delete.element_addr,
return bt_mesh_cfg_mod_sub_va_del(&param, 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(&ctx, (struct bt_mesh_cfg_hb_sub *)&set->heartbeat_sub_set);
return bt_mesh_cfg_hb_sub_set(&param, (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(&ctx, (const struct bt_mesh_cfg_hb_pub *)&set->heartbeat_pub_set);
return bt_mesh_cfg_hb_pub_set(&param, (struct bt_mesh_cfg_hb_pub *)&set->heartbeat_pub_set);
case ESP_BLE_MESH_MODEL_OP_NODE_RESET:
return bt_mesh_cfg_node_reset(&ctx);
return bt_mesh_cfg_node_reset(&param);
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,
@ -577,42 +577,42 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param
.period = set->model_pub_va_set.publish_period,
.transmit = set->model_pub_va_set.publish_retransmit,
};
return bt_mesh_cfg_mod_pub_va_set(&ctx, set->model_pub_va_set.element_addr,
return bt_mesh_cfg_mod_pub_va_set(&param, 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(&ctx, set->model_sub_delete_all.element_addr,
return bt_mesh_cfg_mod_sub_del_all(&param, 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(&ctx, set->net_key_update.net_idx,
return bt_mesh_cfg_net_key_update(&param, 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(&ctx, set->net_key_delete.net_idx);
return bt_mesh_cfg_net_key_delete(&param, set->net_key_delete.net_idx);
case ESP_BLE_MESH_MODEL_OP_APP_KEY_UPDATE:
return bt_mesh_cfg_app_key_update(&ctx, set->app_key_update.net_idx,
return bt_mesh_cfg_app_key_update(&param, 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(&ctx, set->app_key_delete.net_idx,
return bt_mesh_cfg_app_key_delete(&param, 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(&ctx, set->node_identity_set.net_idx,
return bt_mesh_cfg_node_identity_set(&param, 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(&ctx, set->model_app_unbind.element_addr,
return bt_mesh_cfg_mod_app_unbind(&param, 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(&ctx, set->kr_phase_set.net_idx,
return bt_mesh_cfg_kr_phase_set(&param, 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(&ctx, set->net_transmit_set.net_transmit);
return bt_mesh_cfg_net_transmit_set(&param, set->net_transmit_set.net_transmit);
default:
BT_ERR("Invalid Configuration Set opcode 0x%04x", params->opcode);
BT_ERR("Invalid Configuration Set opcode 0x%04x", param.opcode);
return -EINVAL;
}
@ -623,7 +623,6 @@ 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};
bt_mesh_role_param_t role_param = {0};
if (!msg || !msg->arg) {
BT_ERR("%s, Invalid parameter", __func__);
@ -635,12 +634,6 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
switch (msg->act) {
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: {
cb.params = arg->cfg_client_get_state.params;
role_param.model = (struct bt_mesh_model *)cb.params->model;
role_param.role = cb.params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
BT_ERR("Failed to set model role");
break;
}
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) {
@ -650,12 +643,6 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
}
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: {
cb.params = arg->cfg_client_set_state.params;
role_param.model = (struct bt_mesh_model *)cb.params->model;
role_param.role = cb.params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
BT_ERR("Failed to set model role");
break;
}
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) {
@ -727,7 +714,6 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *mo
const u8_t *val, size_t len)
{
esp_ble_mesh_cfg_server_cb_param_t cb_params = {0};
size_t length = 0U;
uint8_t act = 0U;
if (!model || !ctx) {
@ -755,8 +741,7 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *mo
cb_params.ctx.send_ttl = ctx->send_ttl;
if (val && len) {
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
memcpy(&cb_params.value, val, length);
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
}
btc_ble_mesh_config_server_callback(&cb_params, act);

View File

@ -385,7 +385,6 @@ void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
{
esp_ble_mesh_generic_client_cb_param_t cb_params = {0};
esp_ble_mesh_client_common_param_t params = {0};
size_t length = 0U;
uint8_t act = 0U;
if (!model || !ctx) {
@ -426,8 +425,7 @@ void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
cb_params.params = &params;
if (val && len) {
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
memcpy(&cb_params.status_cb, val, length);
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
}
btc_ble_mesh_generic_client_callback(&cb_params, act);
@ -454,7 +452,6 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
btc_ble_mesh_generic_client_args_t *arg = NULL;
esp_ble_mesh_generic_client_cb_param_t cb = {0};
bt_mesh_client_common_param_t common = {0};
bt_mesh_role_param_t role_param = {0};
if (!msg || !msg->arg) {
BT_ERR("%s, Invalid parameter", __func__);
@ -466,12 +463,6 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
switch (msg->act) {
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE: {
params = arg->generic_client_get_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
BT_ERR("Failed to set model role");
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
@ -480,10 +471,10 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
cb.params = arg->generic_client_get_state.params;
cb.error_code = bt_mesh_generic_client_get_state(&common,
(void *)arg->generic_client_get_state.get_state, (void *)&cb.status_cb);
cb.error_code = bt_mesh_generic_client_get_state(&common, 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);
@ -492,12 +483,6 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
}
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE: {
params = arg->generic_client_set_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
BT_ERR("Failed to set model role");
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
@ -506,10 +491,10 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
cb.params = arg->generic_client_set_state.params;
cb.error_code = bt_mesh_generic_client_set_state(&common,
(void *)arg->generic_client_set_state.set_state, (void *)&cb.status_cb);
cb.error_code = bt_mesh_generic_client_set_state(&common, 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);
@ -711,7 +696,6 @@ void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *m
const u8_t *val, size_t len)
{
esp_ble_mesh_generic_server_cb_param_t cb_params = {0};
size_t length = 0U;
uint8_t act = 0U;
if (model == NULL || ctx == NULL) {
@ -745,8 +729,7 @@ void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *m
cb_params.ctx.send_ttl = ctx->send_ttl;
if (val && len) {
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
memcpy(&cb_params.value, val, length);
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
}
btc_ble_mesh_generic_server_callback(&cb_params, act);

View File

@ -21,8 +21,6 @@
#include "health_cli.h"
#include "esp_ble_mesh_health_model_api.h"
extern s32_t health_msg_timeout;
/* 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,
@ -251,7 +249,6 @@ void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
{
esp_ble_mesh_health_client_cb_param_t cb_params = {0};
esp_ble_mesh_client_common_param_t params = {0};
size_t length = 0U;
uint8_t act = 0U;
if (!model || !ctx) {
@ -292,8 +289,7 @@ void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
cb_params.params = &params;
if (val && len) {
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
memcpy(&cb_params.status_cb, val, length);
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
}
btc_ble_mesh_health_client_callback(&cb_params, act);
@ -317,7 +313,7 @@ void btc_ble_mesh_health_publish_callback(u32_t opcode, struct bt_mesh_model *mo
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)
{
struct bt_mesh_msg_ctx ctx = {0};
bt_mesh_client_common_param_t param = {0};
if (params == NULL) {
BT_ERR("%s, Invalid parameter", __func__);
@ -329,23 +325,25 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param
return -EINVAL;
}
ctx.net_idx = params->ctx.net_idx;
ctx.app_idx = params->ctx.app_idx;
ctx.addr = params->ctx.addr;
ctx.send_rel = params->ctx.send_rel;
ctx.send_ttl = params->ctx.send_ttl;
param.opcode = params->opcode;
param.model = (struct bt_mesh_model *)params->model;
param.ctx.net_idx = params->ctx.net_idx;
param.ctx.app_idx = params->ctx.app_idx;
param.ctx.addr = params->ctx.addr;
param.ctx.send_rel = params->ctx.send_rel;
param.ctx.send_ttl = params->ctx.send_ttl;
param.msg_timeout = params->msg_timeout;
param.msg_role = params->msg_role;
health_msg_timeout = params->msg_timeout;
switch (params->opcode) {
switch (param.opcode) {
case ESP_BLE_MESH_MODEL_OP_ATTENTION_GET:
return bt_mesh_health_attention_get(&ctx);
return bt_mesh_health_attention_get(&param);
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_GET:
return bt_mesh_health_period_get(&ctx);
return bt_mesh_health_period_get(&param);
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET:
return bt_mesh_health_fault_get(&ctx, get->fault_get.company_id);
return bt_mesh_health_fault_get(&param, get->fault_get.company_id);
default:
BT_ERR("Invalid Health Get opcode 0x%04x", params->opcode);
BT_ERR("Invalid Health Get opcode 0x%04x", param.opcode);
return -EINVAL;
}
@ -355,40 +353,42 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param
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)
{
struct bt_mesh_msg_ctx ctx = {0};
bt_mesh_client_common_param_t param = {0};
if (params == NULL || set == NULL) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
ctx.net_idx = params->ctx.net_idx;
ctx.app_idx = params->ctx.app_idx;
ctx.addr = params->ctx.addr;
ctx.send_rel = params->ctx.send_rel;
ctx.send_ttl = params->ctx.send_ttl;
param.opcode = params->opcode;
param.model = (struct bt_mesh_model *)params->model;
param.ctx.net_idx = params->ctx.net_idx;
param.ctx.app_idx = params->ctx.app_idx;
param.ctx.addr = params->ctx.addr;
param.ctx.send_rel = params->ctx.send_rel;
param.ctx.send_ttl = params->ctx.send_ttl;
param.msg_timeout = params->msg_timeout;
param.msg_role = params->msg_role;
health_msg_timeout = params->msg_timeout;
switch (params->opcode) {
switch (param.opcode) {
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET:
return bt_mesh_health_attention_set(&ctx, set->attention_set.attention, true);
return bt_mesh_health_attention_set(&param, set->attention_set.attention, true);
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET_UNACK:
return bt_mesh_health_attention_set(&ctx, set->attention_set.attention, false);
return bt_mesh_health_attention_set(&param, set->attention_set.attention, false);
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET:
return bt_mesh_health_period_set(&ctx, set->period_set.fast_period_divisor, true);
return bt_mesh_health_period_set(&param, set->period_set.fast_period_divisor, true);
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET_UNACK:
return bt_mesh_health_period_set(&ctx, set->period_set.fast_period_divisor, false);
return bt_mesh_health_period_set(&param, set->period_set.fast_period_divisor, false);
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST:
return bt_mesh_health_fault_test(&ctx, set->fault_test.company_id, set->fault_test.test_id, true);
return bt_mesh_health_fault_test(&param, 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(&ctx, set->fault_test.company_id, set->fault_test.test_id, false);
return bt_mesh_health_fault_test(&param, 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(&ctx, set->fault_clear.company_id, true);
return bt_mesh_health_fault_clear(&param, set->fault_clear.company_id, true);
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR_UNACK:
return bt_mesh_health_fault_clear(&ctx, set->fault_clear.company_id, false);
return bt_mesh_health_fault_clear(&param, set->fault_clear.company_id, false);
default:
BT_ERR("Invalid Health Set opcode 0x%04x", params->opcode);
BT_ERR("Invalid Health Set opcode 0x%04x", param.opcode);
return -EINVAL;
}
@ -399,7 +399,6 @@ 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};
bt_mesh_role_param_t role_param = {0};
if (!msg || !msg->arg) {
BT_ERR("%s, Invalid parameter", __func__);
@ -411,12 +410,6 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
switch (msg->act) {
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE: {
cb.params = arg->health_client_get_state.params;
role_param.model = (struct bt_mesh_model *)cb.params->model;
role_param.role = cb.params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
BT_ERR("Failed to set model role");
break;
}
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) {
@ -427,12 +420,6 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
}
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE: {
cb.params = arg->health_client_set_state.params;
role_param.model = (struct bt_mesh_model *)cb.params->model;
role_param.role = cb.params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
BT_ERR("Failed to set model role");
break;
}
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) {

View File

@ -229,7 +229,6 @@ void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
{
esp_ble_mesh_light_client_cb_param_t cb_params = {0};
esp_ble_mesh_client_common_param_t params = {0};
size_t length = 0U;
uint8_t act = 0U;
if (!model || !ctx) {
@ -270,8 +269,7 @@ void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
cb_params.params = &params;
if (val && len) {
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
memcpy(&cb_params.status_cb, val, length);
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
}
btc_ble_mesh_lighting_client_callback(&cb_params, act);
@ -298,7 +296,6 @@ 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 common = {0};
bt_mesh_role_param_t role_param = {0};
if (!msg || !msg->arg) {
BT_ERR("%s, Invalid parameter", __func__);
@ -310,12 +307,6 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
switch (msg->act) {
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE: {
params = arg->light_client_get_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
BT_ERR("Failed to set model role");
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
@ -324,10 +315,10 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
cb.params = arg->light_client_get_state.params;
cb.error_code = bt_mesh_light_client_get_state(&common,
(void *)arg->light_client_get_state.get_state, (void *)&cb.status_cb);
cb.error_code = bt_mesh_light_client_get_state(&common, 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);
@ -336,12 +327,6 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
}
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE: {
params = arg->light_client_set_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
BT_ERR("Failed to set model role");
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
@ -350,10 +335,10 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
cb.params = arg->light_client_set_state.params;
cb.error_code = bt_mesh_light_client_set_state(&common,
(void *)arg->light_client_set_state.set_state, (void *)&cb.status_cb);
cb.error_code = bt_mesh_light_client_set_state(&common, 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);
@ -523,7 +508,6 @@ void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *
const u8_t *val, size_t len)
{
esp_ble_mesh_lighting_server_cb_param_t cb_params = {0};
size_t length = 0U;
uint8_t act = 0U;
if (model == NULL || ctx == NULL) {
@ -560,8 +544,7 @@ void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *
cb_params.ctx.send_ttl = ctx->send_ttl;
if (val && len) {
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
memcpy(&cb_params.value, val, length);
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
}
btc_ble_mesh_lighting_server_callback(&cb_params, act);

View File

@ -1978,11 +1978,12 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg)
switch (msg->act) {
case BTC_BLE_MESH_ACT_MODEL_PUBLISH: {
if (arg->model_publish.device_role == PROVISIONER) {
bt_mesh_role_param_t common = {0};
common.model = (struct bt_mesh_model *)(arg->model_publish.model);
common.role = arg->model_publish.device_role;
if (bt_mesh_set_client_model_role(&common)) {
BT_ERR("Failed to set model role");
/* Currently Provisioner only supports client model */
err = bt_mesh_set_client_model_role((struct bt_mesh_model *)arg->model_publish.model,
arg->model_publish.device_role);
if (err) {
BT_ERR("Failed to set client role");
btc_ble_mesh_model_publish_comp_cb(arg->model_publish.model, err);
break;
}
}
@ -1995,10 +1996,14 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg)
struct net_buf_simple *buf = bt_mesh_alloc_buf(arg->model_send.length + BLE_MESH_MIC_SHORT);
if (!buf) {
BT_ERR("%s, Out of memory", __func__);
btc_ble_mesh_model_send_comp_cb(arg->model_send.model, arg->model_send.ctx,
arg->model_send.opcode, -ENOMEM);
break;
}
net_buf_simple_add_mem(buf, arg->model_send.data, arg->model_send.length);
arg->model_send.ctx->srv_send = true;
err = bt_mesh_model_send((struct bt_mesh_model *)arg->model_send.model,
(struct bt_mesh_msg_ctx *)arg->model_send.ctx,
buf, NULL, NULL);
@ -2008,26 +2013,30 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg)
break;
}
case BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND: {
bt_mesh_role_param_t common = {0};
/* arg->model_send.length contains opcode & message, plus extra 4-bytes TransMIC */
struct net_buf_simple *buf = bt_mesh_alloc_buf(arg->model_send.length + BLE_MESH_MIC_SHORT);
if (!buf) {
BT_ERR("%s, Out of memory", __func__);
btc_ble_mesh_model_send_comp_cb(arg->model_send.model, arg->model_send.ctx,
arg->model_send.opcode, -ENOMEM);
break;
}
net_buf_simple_add_mem(buf, arg->model_send.data, arg->model_send.length);
arg->model_send.ctx->srv_send = false;
common.model = (struct bt_mesh_model *)(arg->model_send.model);
common.role = arg->model_send.device_role;
if (bt_mesh_set_client_model_role(&common)) {
BT_ERR("Failed to set model role");
break;
}
err = bt_mesh_client_send_msg((struct bt_mesh_model *)arg->model_send.model,
arg->model_send.opcode,
(struct bt_mesh_msg_ctx *)arg->model_send.ctx, buf,
btc_ble_mesh_client_model_timeout_cb, arg->model_send.msg_timeout,
arg->model_send.need_rsp, NULL, NULL);
bt_mesh_client_common_param_t param = {
.opcode = arg->model_send.opcode,
.model = (struct bt_mesh_model *)arg->model_send.model,
.ctx.net_idx = arg->model_send.ctx->net_idx,
.ctx.app_idx = arg->model_send.ctx->app_idx,
.ctx.addr = arg->model_send.ctx->addr,
.ctx.send_rel = arg->model_send.ctx->send_rel,
.ctx.send_ttl = arg->model_send.ctx->send_ttl,
.ctx.srv_send = false,
.msg_timeout = arg->model_send.msg_timeout,
.msg_role = arg->model_send.device_role,
};
err = bt_mesh_client_send_msg(&param, buf, arg->model_send.need_rsp,
btc_ble_mesh_client_model_timeout_cb);
bt_mesh_free_buf(buf);
btc_ble_mesh_model_send_comp_cb(arg->model_send.model, arg->model_send.ctx,
arg->model_send.opcode, err);

View File

@ -467,7 +467,6 @@ void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
{
esp_ble_mesh_sensor_client_cb_param_t cb_params = {0};
esp_ble_mesh_client_common_param_t params = {0};
size_t length = 0U;
uint8_t act = 0U;
if (!model || !ctx) {
@ -508,8 +507,7 @@ void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
cb_params.params = &params;
if (val && len) {
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
memcpy(&cb_params.status_cb, val, length);
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
}
btc_ble_mesh_sensor_client_callback(&cb_params, act);
@ -536,7 +534,6 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
btc_ble_mesh_sensor_client_args_t *arg = NULL;
esp_ble_mesh_sensor_client_cb_param_t cb = {0};
bt_mesh_client_common_param_t common = {0};
bt_mesh_role_param_t role_param = {0};
if (!msg || !msg->arg) {
BT_ERR("%s, Invalid parameter", __func__);
@ -548,12 +545,6 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
switch (msg->act) {
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE: {
params = arg->sensor_client_get_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
BT_ERR("Failed to set model role");
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
@ -562,10 +553,10 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
cb.params = arg->sensor_client_get_state.params;
cb.error_code = bt_mesh_sensor_client_get_state(&common,
(void *)arg->sensor_client_get_state.get_state, (void *)&cb.status_cb);
cb.error_code = bt_mesh_sensor_client_get_state(&common, 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);
@ -574,12 +565,6 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
}
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE: {
params = arg->sensor_client_set_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
BT_ERR("Failed to set model role");
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
@ -588,10 +573,10 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
cb.params = arg->sensor_client_set_state.params;
cb.error_code = bt_mesh_sensor_client_set_state(&common,
(void *)arg->sensor_client_set_state.set_state, (void *)&cb.status_cb);
cb.error_code = bt_mesh_sensor_client_set_state(&common, 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);
@ -843,7 +828,6 @@ void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *mo
const u8_t *val, size_t len)
{
esp_ble_mesh_sensor_server_cb_param_t cb_params = {0};
size_t length = 0U;
uint8_t act = 0U;
if (model == NULL || ctx == NULL) {
@ -877,8 +861,7 @@ void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *mo
cb_params.ctx.send_ttl = ctx->send_ttl;
if (val && len) {
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
memcpy(&cb_params.value, val, length);
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
}
btc_ble_mesh_sensor_server_callback(&cb_params, act);

View File

@ -231,7 +231,6 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
{
esp_ble_mesh_time_scene_client_cb_param_t cb_params = {0};
esp_ble_mesh_client_common_param_t params = {0};
size_t length = 0U;
uint8_t act = 0U;
if (!model || !ctx) {
@ -272,8 +271,7 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
cb_params.params = &params;
if (val && len) {
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
memcpy(&cb_params.status_cb, val, length);
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
}
btc_ble_mesh_time_scene_client_callback(&cb_params, act);
@ -300,7 +298,6 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
esp_ble_mesh_client_common_param_t *params = NULL;
esp_ble_mesh_time_scene_client_cb_param_t cb = {0};
bt_mesh_client_common_param_t common = {0};
bt_mesh_role_param_t role_param = {0};
if (!msg || !msg->arg) {
BT_ERR("%s, Invalid parameter", __func__);
@ -312,12 +309,6 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
switch (msg->act) {
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE: {
params = arg->time_scene_client_get_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
BT_ERR("Failed to set model role");
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
@ -326,10 +317,10 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
cb.params = arg->time_scene_client_get_state.params;
cb.error_code = bt_mesh_time_scene_client_get_state(&common,
(void *)arg->time_scene_client_get_state.get_state, (void *)&cb.status_cb);
cb.error_code = bt_mesh_time_scene_client_get_state(&common, 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);
@ -338,12 +329,6 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
}
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE: {
params = arg->time_scene_client_set_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
BT_ERR("Failed to set model role");
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
@ -352,10 +337,10 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
cb.params = arg->time_scene_client_set_state.params;
cb.error_code = bt_mesh_time_scene_client_set_state(&common,
(void *)arg->time_scene_client_set_state.set_state, (void *)&cb.status_cb);
cb.error_code = bt_mesh_time_scene_client_set_state(&common, 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);
@ -426,7 +411,6 @@ void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model
const u8_t *val, size_t len)
{
esp_ble_mesh_time_scene_server_cb_param_t cb_params = {0};
size_t length = 0U;
uint8_t act = 0U;
if (model == NULL || ctx == NULL) {
@ -463,8 +447,7 @@ void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model
cb_params.ctx.send_ttl = ctx->send_ttl;
if (val && len) {
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
memcpy(&cb_params.value, val, length);
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
}
btc_ble_mesh_time_scene_server_callback(&cb_params, act);

File diff suppressed because it is too large Load Diff

View File

@ -18,10 +18,6 @@
#include "mesh_common.h"
#include "health_cli.h"
s32_t health_msg_timeout;
static bt_mesh_health_client_t *health_cli;
static const bt_mesh_client_op_pair_t health_op_pair[] = {
{ OP_HEALTH_FAULT_GET, OP_HEALTH_FAULT_STATUS },
{ OP_HEALTH_FAULT_CLEAR, OP_HEALTH_FAULT_STATUS },
@ -85,9 +81,9 @@ static void timeout_handler(struct k_work *work)
return;
}
static void health_client_cancel(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
void *status, size_t len)
static void health_client_recv_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
void *status, size_t len)
{
bt_mesh_client_node_t *node = NULL;
struct net_buf_simple buf = {0};
@ -136,8 +132,7 @@ static void health_client_cancel(struct bt_mesh_model *model,
switch (ctx->recv_op) {
case OP_HEALTH_FAULT_STATUS: {
struct bt_mesh_health_fault_status *val;
val = (struct bt_mesh_health_fault_status *)status;
struct bt_mesh_health_fault_status *val = status;
bt_mesh_free_buf(val->fault_array);
break;
}
@ -171,7 +166,7 @@ static void health_fault_status(struct bt_mesh_model *model,
net_buf_simple_add_mem(status.fault_array, buf->data, buf->len);
health_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_health_fault_status));
health_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_health_fault_status));
}
static void health_current_status(struct bt_mesh_model *model,
@ -194,7 +189,7 @@ static void health_current_status(struct bt_mesh_model *model,
net_buf_simple_add_mem(status.fault_array, buf->data, buf->len);
health_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_health_current_status));
health_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_health_current_status));
}
static void health_period_status(struct bt_mesh_model *model,
@ -209,7 +204,7 @@ static void health_period_status(struct bt_mesh_model *model,
status = net_buf_simple_pull_u8(buf);
health_client_cancel(model, ctx, &status, sizeof(u8_t));
health_client_recv_status(model, ctx, &status, sizeof(u8_t));
}
static void health_attention_status(struct bt_mesh_model *model,
@ -224,7 +219,7 @@ static void health_attention_status(struct bt_mesh_model *model,
status = net_buf_simple_pull_u8(buf);
health_client_cancel(model, ctx, &status, sizeof(u8_t));
health_client_recv_status(model, ctx, &status, sizeof(u8_t));
}
const struct bt_mesh_model_op bt_mesh_health_cli_op[] = {
@ -235,207 +230,77 @@ const struct bt_mesh_model_op bt_mesh_health_cli_op[] = {
BLE_MESH_MODEL_OP_END,
};
int bt_mesh_health_attention_get(struct bt_mesh_msg_ctx *ctx)
int bt_mesh_health_attention_get(bt_mesh_client_common_param_t *param)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_GET, 0);
int err = 0;
if (!ctx || !ctx->addr) {
return -EINVAL;
}
bt_mesh_model_msg_init(&msg, OP_ATTENTION_GET);
err = bt_mesh_client_send_msg(health_cli->model, OP_ATTENTION_GET, ctx,
&msg, timeout_handler, health_msg_timeout,
true, NULL, NULL);
if (err) {
BT_ERR("%s, send failed (err %d)", __func__, err);
}
return err;
return bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
}
int bt_mesh_health_attention_set(struct bt_mesh_msg_ctx *ctx,
int bt_mesh_health_attention_set(bt_mesh_client_common_param_t *param,
u8_t attention, bool need_ack)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_SET, 1);
u32_t opcode = 0U;
int err = 0;
if (!ctx || !ctx->addr) {
return -EINVAL;
}
if (need_ack) {
opcode = OP_ATTENTION_SET;
} else {
opcode = OP_ATTENTION_SET_UNREL;
}
bt_mesh_model_msg_init(&msg, opcode);
bt_mesh_model_msg_init(&msg, need_ack ? OP_ATTENTION_SET : OP_ATTENTION_SET_UNREL);
net_buf_simple_add_u8(&msg, attention);
err = bt_mesh_client_send_msg(health_cli->model, opcode, ctx, &msg,
timeout_handler, health_msg_timeout,
need_ack, NULL, NULL);
if (err) {
BT_ERR("%s, send failed (err %d)", __func__, err);
}
return err;
return bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler);
}
int bt_mesh_health_period_get(struct bt_mesh_msg_ctx *ctx)
int bt_mesh_health_period_get(bt_mesh_client_common_param_t *param)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_GET, 0);
int err = 0;
if (!ctx || !ctx->addr) {
return -EINVAL;
}
bt_mesh_model_msg_init(&msg, OP_HEALTH_PERIOD_GET);
err = bt_mesh_client_send_msg(health_cli->model, OP_HEALTH_PERIOD_GET,
ctx, &msg, timeout_handler, health_msg_timeout,
true, NULL, NULL);
if (err) {
BT_ERR("%s, send failed (err %d)", __func__, err);
}
return err;
return bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
}
int bt_mesh_health_period_set(struct bt_mesh_msg_ctx *ctx,
int bt_mesh_health_period_set(bt_mesh_client_common_param_t *param,
u8_t divisor, bool need_ack)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_SET, 1);
u32_t opcode = 0U;
int err = 0;
if (!ctx || !ctx->addr) {
return -EINVAL;
}
if (need_ack) {
opcode = OP_HEALTH_PERIOD_SET;
} else {
opcode = OP_HEALTH_PERIOD_SET_UNREL;
}
bt_mesh_model_msg_init(&msg, opcode);
bt_mesh_model_msg_init(&msg, need_ack ? OP_HEALTH_PERIOD_SET : OP_HEALTH_PERIOD_SET_UNREL);
net_buf_simple_add_u8(&msg, divisor);
err = bt_mesh_client_send_msg(health_cli->model, opcode, ctx, &msg,
timeout_handler, health_msg_timeout,
need_ack, NULL, NULL);
if (err) {
BT_ERR("%s, send failed (err %d)", __func__, err);
}
return err;
return bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler);
}
int bt_mesh_health_fault_test(struct bt_mesh_msg_ctx *ctx,
int bt_mesh_health_fault_test(bt_mesh_client_common_param_t *param,
u16_t cid, u8_t test_id, bool need_ack)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_TEST, 3);
u32_t opcode = 0U;
int err = 0;
if (!ctx || !ctx->addr) {
return -EINVAL;
}
if (need_ack) {
opcode = OP_HEALTH_FAULT_TEST;
} else {
opcode = OP_HEALTH_FAULT_TEST_UNREL;
}
bt_mesh_model_msg_init(&msg, opcode);
bt_mesh_model_msg_init(&msg, need_ack ? OP_HEALTH_FAULT_TEST : OP_HEALTH_FAULT_TEST_UNREL);
net_buf_simple_add_u8(&msg, test_id);
net_buf_simple_add_le16(&msg, cid);
err = bt_mesh_client_send_msg(health_cli->model, opcode, ctx, &msg,
timeout_handler, health_msg_timeout,
need_ack, NULL, NULL);
if (err) {
BT_ERR("%s, send failed (err %d)", __func__, err);
}
return err;
return bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler);
}
int bt_mesh_health_fault_clear(struct bt_mesh_msg_ctx *ctx,
int bt_mesh_health_fault_clear(bt_mesh_client_common_param_t *param,
u16_t cid, bool need_ack)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_CLEAR, 2);
u32_t opcode = 0U;
int err = 0;
if (!ctx || !ctx->addr) {
return -EINVAL;
}
if (need_ack) {
opcode = OP_HEALTH_FAULT_CLEAR;
} else {
opcode = OP_HEALTH_FAULT_CLEAR_UNREL;
}
bt_mesh_model_msg_init(&msg, opcode);
bt_mesh_model_msg_init(&msg, need_ack ? OP_HEALTH_FAULT_CLEAR : OP_HEALTH_FAULT_CLEAR_UNREL);
net_buf_simple_add_le16(&msg, cid);
err = bt_mesh_client_send_msg(health_cli->model, opcode, ctx, &msg,
timeout_handler, health_msg_timeout,
need_ack, NULL, NULL);
if (err) {
BT_ERR("%s, send failed (err %d)", __func__, err);
}
return err;
return bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler);
}
int bt_mesh_health_fault_get(struct bt_mesh_msg_ctx *ctx, u16_t cid)
int bt_mesh_health_fault_get(bt_mesh_client_common_param_t *param, u16_t cid)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_GET, 2);
int err = 0;
if (!ctx || !ctx->addr) {
return -EINVAL;
}
bt_mesh_model_msg_init(&msg, OP_HEALTH_FAULT_GET);
net_buf_simple_add_le16(&msg, cid);
err = bt_mesh_client_send_msg(health_cli->model, OP_HEALTH_FAULT_GET, ctx,
&msg, timeout_handler, health_msg_timeout,
true, NULL, NULL);
if (err) {
BT_ERR("%s, send failed (err %d)", __func__, err);
}
return err;
}
s32_t bt_mesh_health_cli_timeout_get(void)
{
return health_msg_timeout;
}
void bt_mesh_health_cli_timeout_set(s32_t timeout)
{
health_msg_timeout = timeout;
}
int bt_mesh_health_cli_set(struct bt_mesh_model *model)
{
if (!model || !model->user_data) {
BT_ERR("No Health Client context for given model");
return -EINVAL;
}
health_cli = model->user_data;
return 0;
return bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
}
int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary)
@ -475,11 +340,6 @@ int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary)
bt_mesh_health_client_mutex_new();
/* Set the default health client pointer */
if (!health_cli) {
health_cli = client;
}
return 0;
}
@ -509,9 +369,5 @@ int bt_mesh_health_cli_deinit(struct bt_mesh_model *model, bool primary)
bt_mesh_health_client_mutex_free();
if (health_cli) {
health_cli = NULL;
}
return 0;
}

View File

@ -34,36 +34,39 @@ extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_CFG_CLI, \
bt_mesh_cfg_cli_op, NULL, cli_data)
int bt_mesh_cfg_comp_data_get(struct bt_mesh_msg_ctx *ctx, u8_t page);
int bt_mesh_cfg_comp_data_get(bt_mesh_client_common_param_t *param, u8_t page);
int bt_mesh_cfg_beacon_get(struct bt_mesh_msg_ctx *ctx);
int bt_mesh_cfg_beacon_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_beacon_set(struct bt_mesh_msg_ctx *ctx, u8_t val);
int bt_mesh_cfg_beacon_set(bt_mesh_client_common_param_t *param, u8_t val);
int bt_mesh_cfg_ttl_get(struct bt_mesh_msg_ctx *ctx);
int bt_mesh_cfg_ttl_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_ttl_set(struct bt_mesh_msg_ctx *ctx, u8_t val);
int bt_mesh_cfg_ttl_set(bt_mesh_client_common_param_t *param, u8_t val);
int bt_mesh_cfg_friend_get(struct bt_mesh_msg_ctx *ctx);
int bt_mesh_cfg_friend_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_friend_set(struct bt_mesh_msg_ctx *ctx, u8_t val);
int bt_mesh_cfg_friend_set(bt_mesh_client_common_param_t *param, u8_t val);
int bt_mesh_cfg_gatt_proxy_get(struct bt_mesh_msg_ctx *ctx);
int bt_mesh_cfg_gatt_proxy_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_gatt_proxy_set(struct bt_mesh_msg_ctx *ctx, u8_t val);
int bt_mesh_cfg_gatt_proxy_set(bt_mesh_client_common_param_t *param, u8_t val);
int bt_mesh_cfg_relay_get(struct bt_mesh_msg_ctx *ctx);
int bt_mesh_cfg_relay_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_relay_set(struct bt_mesh_msg_ctx *ctx, u8_t new_relay, u8_t new_transmit);
int bt_mesh_cfg_relay_set(bt_mesh_client_common_param_t *param,
u8_t relay, u8_t retransmit);
int bt_mesh_cfg_net_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx,
const u8_t net_key[16]);
int bt_mesh_cfg_net_key_add(bt_mesh_client_common_param_t *param,
u16_t net_idx, const u8_t net_key[16]);
int bt_mesh_cfg_app_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx,
u16_t key_app_idx, const u8_t app_key[16]);
int bt_mesh_cfg_app_key_add(bt_mesh_client_common_param_t *param,
u16_t net_idx, u16_t app_idx,
const u8_t app_key[16]);
int bt_mesh_cfg_mod_app_bind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
u16_t mod_app_idx, u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_app_bind(bt_mesh_client_common_param_t *param,
u16_t elem_addr, u16_t app_idx,
u16_t mod_id, u16_t cid);
struct bt_mesh_cfg_mod_pub {
u16_t addr;
@ -74,30 +77,36 @@ struct bt_mesh_cfg_mod_pub {
u8_t transmit;
};
int bt_mesh_cfg_mod_pub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_pub_get(bt_mesh_client_common_param_t *param,
u16_t elem_addr, u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_pub_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
u16_t mod_id, u16_t cid,
int bt_mesh_cfg_mod_pub_set(bt_mesh_client_common_param_t *param,
u16_t elem_addr, u16_t mod_id, u16_t cid,
struct bt_mesh_cfg_mod_pub *pub);
int bt_mesh_cfg_mod_sub_add(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
u16_t sub_addr, u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_sub_add(bt_mesh_client_common_param_t *param,
u16_t elem_addr, u16_t sub_addr,
u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_sub_del(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
u16_t sub_addr, u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_sub_del(bt_mesh_client_common_param_t *param,
u16_t elem_addr, u16_t sub_addr,
u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_sub_overwrite(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
u16_t sub_addr, u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_sub_overwrite(bt_mesh_client_common_param_t *param,
u16_t elem_addr, u16_t sub_addr,
u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_sub_va_add(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
const u8_t label[16], u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_sub_va_add(bt_mesh_client_common_param_t *param,
u16_t elem_addr, const u8_t label[16],
u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_sub_va_del(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
const u8_t label[16], u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_sub_va_del(bt_mesh_client_common_param_t *param,
u16_t elem_addr, const u8_t label[16],
u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_sub_va_overwrite(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
const u8_t label[16], u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_sub_va_overwrite(bt_mesh_client_common_param_t *param,
u16_t elem_addr, const u8_t label[16],
u16_t mod_id, u16_t cid);
struct bt_mesh_cfg_hb_sub {
u16_t src;
@ -105,10 +114,10 @@ struct bt_mesh_cfg_hb_sub {
u8_t period;
};
int bt_mesh_cfg_hb_sub_set(struct bt_mesh_msg_ctx *ctx,
int bt_mesh_cfg_hb_sub_set(bt_mesh_client_common_param_t *param,
struct bt_mesh_cfg_hb_sub *sub);
int bt_mesh_cfg_hb_sub_get(struct bt_mesh_msg_ctx *ctx);
int bt_mesh_cfg_hb_sub_get(bt_mesh_client_common_param_t *param);
struct bt_mesh_cfg_hb_pub {
u16_t dst;
@ -119,15 +128,12 @@ struct bt_mesh_cfg_hb_pub {
u16_t net_idx;
};
int bt_mesh_cfg_hb_pub_set(struct bt_mesh_msg_ctx *ctx,
const struct bt_mesh_cfg_hb_pub *pub);
int bt_mesh_cfg_hb_pub_set(bt_mesh_client_common_param_t *param,
struct bt_mesh_cfg_hb_pub *pub);
int bt_mesh_cfg_hb_pub_get(struct bt_mesh_msg_ctx *ctx);
int bt_mesh_cfg_hb_pub_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_node_reset(struct bt_mesh_msg_ctx *ctx);
s32_t bt_mesh_cfg_cli_timeout_get(void);
void bt_mesh_cfg_cli_timeout_set(s32_t timeout);
int bt_mesh_cfg_node_reset(bt_mesh_client_common_param_t *param);
/* Configuration Client Status Message Context */
@ -244,53 +250,61 @@ struct bt_mesh_cfg_lpn_pollto_status {
s32_t timeout;
};
int bt_mesh_cfg_mod_pub_va_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
u16_t mod_id, u16_t cid, const u8_t label[16],
int bt_mesh_cfg_mod_pub_va_set(bt_mesh_client_common_param_t *param,
u16_t elem_addr, u16_t mod_id,
u16_t cid, const u8_t label[16],
struct bt_mesh_cfg_mod_pub *pub);
int bt_mesh_cfg_mod_sub_del_all(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_sub_del_all(bt_mesh_client_common_param_t *param,
u16_t elem_addr, u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_sub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, u16_t mod_id);
int bt_mesh_cfg_mod_sub_get(bt_mesh_client_common_param_t *param,
u16_t elem_addr, u16_t mod_id);
int bt_mesh_cfg_mod_sub_get_vnd(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_sub_get_vnd(bt_mesh_client_common_param_t *param,
u16_t elem_addr, u16_t mod_id, u16_t cid);
int bt_mesh_cfg_net_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx,
const u8_t net_key[16]);
int bt_mesh_cfg_net_key_update(bt_mesh_client_common_param_t *param,
u16_t net_idx, const u8_t net_key[16]);
int bt_mesh_cfg_net_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx);
int bt_mesh_cfg_net_key_delete(bt_mesh_client_common_param_t *param, u16_t net_idx);
int bt_mesh_cfg_net_key_get(struct bt_mesh_msg_ctx *ctx);
int bt_mesh_cfg_net_key_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_app_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx,
u16_t app_idx, const u8_t app_key[16]);
int bt_mesh_cfg_app_key_update(bt_mesh_client_common_param_t *param,
u16_t net_idx, u16_t app_idx,
const u8_t app_key[16]);
int bt_mesh_cfg_app_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u16_t app_idx);
int bt_mesh_cfg_app_key_delete(bt_mesh_client_common_param_t *param,
u16_t net_idx, u16_t app_idx);
int bt_mesh_cfg_app_key_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx);
int bt_mesh_cfg_app_key_get(bt_mesh_client_common_param_t *param, u16_t net_idx);
int bt_mesh_cfg_node_identity_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx);
int bt_mesh_cfg_node_identity_get(bt_mesh_client_common_param_t *param, u16_t net_idx);
int bt_mesh_cfg_node_identity_set(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u8_t identity);
int bt_mesh_cfg_node_identity_set(bt_mesh_client_common_param_t *param,
u16_t net_idx, u8_t identity);
int bt_mesh_cfg_mod_app_unbind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
u16_t app_idx, u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_app_unbind(bt_mesh_client_common_param_t *param,
u16_t elem_addr, u16_t app_idx,
u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_app_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, u16_t mod_id);
int bt_mesh_cfg_mod_app_get(bt_mesh_client_common_param_t *param,
u16_t elem_addr, u16_t mod_id);
int bt_mesh_cfg_mod_app_get_vnd(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
u16_t mod_id, u16_t cid);
int bt_mesh_cfg_mod_app_get_vnd(bt_mesh_client_common_param_t *param,
u16_t elem_addr, u16_t mod_id, u16_t cid);
int bt_mesh_cfg_kr_phase_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx);
int bt_mesh_cfg_kr_phase_get(bt_mesh_client_common_param_t *param, u16_t net_idx);
int bt_mesh_cfg_kr_phase_set(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u8_t transition);
int bt_mesh_cfg_kr_phase_set(bt_mesh_client_common_param_t *param,
u16_t net_idx, u8_t transition);
int bt_mesh_cfg_lpn_timeout_get(struct bt_mesh_msg_ctx *ctx, u16_t lpn_addr);
int bt_mesh_cfg_lpn_timeout_get(bt_mesh_client_common_param_t *param, u16_t lpn_addr);
int bt_mesh_cfg_net_transmit_get(struct bt_mesh_msg_ctx *ctx);
int bt_mesh_cfg_net_transmit_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_net_transmit_set(struct bt_mesh_msg_ctx *ctx, u8_t transmit);
int bt_mesh_cfg_net_transmit_set(bt_mesh_client_common_param_t *param, u8_t transmit);
#ifdef __cplusplus
}

View File

@ -34,29 +34,24 @@ extern const struct bt_mesh_model_op bt_mesh_health_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_HEALTH_CLI, \
bt_mesh_health_cli_op, NULL, cli_data)
int bt_mesh_health_cli_set(struct bt_mesh_model *model);
int bt_mesh_health_fault_get(bt_mesh_client_common_param_t *param, u16_t cid);
int bt_mesh_health_fault_get(struct bt_mesh_msg_ctx *ctx, u16_t cid);
int bt_mesh_health_fault_clear(bt_mesh_client_common_param_t *param,
u16_t cid, bool need_ack);
int bt_mesh_health_fault_clear(struct bt_mesh_msg_ctx *ctx, u16_t cid,
bool need_ack);
int bt_mesh_health_fault_test(struct bt_mesh_msg_ctx *ctx,
int bt_mesh_health_fault_test(bt_mesh_client_common_param_t *param,
u16_t cid, u8_t test_id, bool need_ack);
int bt_mesh_health_period_get(struct bt_mesh_msg_ctx *ctx);
int bt_mesh_health_period_get(bt_mesh_client_common_param_t *param);
int bt_mesh_health_period_set(struct bt_mesh_msg_ctx *ctx,
int bt_mesh_health_period_set(bt_mesh_client_common_param_t *param,
u8_t divisor, bool need_ack);
int bt_mesh_health_attention_get(struct bt_mesh_msg_ctx *ctx);
int bt_mesh_health_attention_get(bt_mesh_client_common_param_t *param);
int bt_mesh_health_attention_set(struct bt_mesh_msg_ctx *ctx,
int bt_mesh_health_attention_set(bt_mesh_client_common_param_t *param,
u8_t attention, bool need_ack);
s32_t bt_mesh_health_cli_timeout_get(void);
void bt_mesh_health_cli_timeout_set(s32_t timeout);
/* Health Client Status Message Context */
struct bt_mesh_health_current_status {

View File

@ -251,26 +251,21 @@ static const struct bt_mesh_send_cb send_cb = {
.end = NULL,
};
int bt_mesh_client_send_msg(struct bt_mesh_model *model,
u32_t opcode,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *msg,
k_work_handler_t timer_handler,
s32_t timeout, bool need_ack,
const struct bt_mesh_send_cb *cb,
void *cb_data)
int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param,
struct net_buf_simple *msg, bool need_ack,
k_work_handler_t timer_handler)
{
bt_mesh_client_internal_data_t *internal = NULL;
bt_mesh_client_user_data_t *client = NULL;
bt_mesh_client_node_t *node = NULL;
int err = 0;
if (!model || !ctx || !msg) {
if (!param || !param->model || !msg) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
client = (bt_mesh_client_user_data_t *)model->user_data;
client = (bt_mesh_client_user_data_t *)param->model->user_data;
if (!client) {
BT_ERR("Invalid client user data");
return -EINVAL;
@ -282,23 +277,28 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
return -EINVAL;
}
if (ctx->addr == BLE_MESH_ADDR_UNASSIGNED) {
BT_ERR("Invalid DST 0x%04x", ctx->addr);
if (param->ctx.addr == BLE_MESH_ADDR_UNASSIGNED) {
BT_ERR("Invalid DST 0x%04x", param->ctx.addr);
return -EINVAL;
}
if (!need_ack) {
/* If this is an unack message, send it directly. */
return bt_mesh_model_send(model, ctx, msg, cb, cb_data);
if (bt_mesh_set_client_model_role(param->model, param->msg_role)) {
BT_ERR("Failed to set client role");
return -EIO;
}
if (!BLE_MESH_ADDR_IS_UNICAST(ctx->addr)) {
/* If an acknowledged message is not sent to a unicast address,
* for example to a group/virtual address, then all the
* corresponding responses will be treated as publish messages.
* And no timeout will be used for the message.
if (need_ack == false || !BLE_MESH_ADDR_IS_UNICAST(param->ctx.addr)) {
/* 1. If this is an unacknowledged message, send it directly.
* 2. If this is an acknowledged message, but the destination
* is not a unicast address, e.g. a group/virtual address,
* then all the corresponding responses will be treated as
* publish messages, and no timeout will be used.
*/
return bt_mesh_model_send(model, ctx, msg, cb, cb_data);
err = bt_mesh_model_send(param->model, &param->ctx, msg, param->cb, param->cb_data);
if (err) {
BT_ERR("Failed to send client message 0x%08x", param->opcode);
}
return err;
}
if (!timer_handler) {
@ -306,8 +306,8 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
return -EINVAL;
}
if (bt_mesh_client_check_node_in_list(&internal->queue, ctx->addr)) {
BT_ERR("Busy sending message to DST 0x%04x", ctx->addr);
if (bt_mesh_client_check_node_in_list(&internal->queue, param->ctx.addr)) {
BT_ERR("Busy sending message to DST 0x%04x", param->ctx.addr);
return -EBUSY;
}
@ -318,16 +318,17 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
return -ENOMEM;
}
memcpy(&node->ctx, ctx, sizeof(struct bt_mesh_msg_ctx));
node->ctx.model = model;
node->opcode = opcode;
node->op_pending = bt_mesh_client_get_status_op(client->op_pair, client->op_pair_size, opcode);
memcpy(&node->ctx, &param->ctx, sizeof(struct bt_mesh_msg_ctx));
node->ctx.model = param->model;
node->opcode = param->opcode;
node->op_pending = bt_mesh_client_get_status_op(client->op_pair, client->op_pair_size, param->opcode);
if (node->op_pending == 0U) {
BT_ERR("Not found the status opcode in op_pair list");
bt_mesh_free(node);
return -EINVAL;
}
node->timeout = bt_mesh_client_calc_timeout(ctx, msg, opcode, timeout ? timeout : CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT);
node->timeout = bt_mesh_client_calc_timeout(&param->ctx, msg, param->opcode,
param->msg_timeout ? param->msg_timeout : CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT);
if (k_delayed_work_init(&node->timer, timer_handler)) {
BT_ERR("Failed to create a timer");
@ -343,7 +344,7 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
* Due to the higher priority of adv_thread (than btc task), we need to
* send the packet after the list item "node" is initialized properly.
*/
err = bt_mesh_model_send(model, ctx, msg, &send_cb, node);
err = bt_mesh_model_send(param->model, &param->ctx, msg, &send_cb, node);
if (err) {
BT_ERR("Failed to send client message 0x%08x", node->opcode);
k_delayed_work_free(&node->timer);
@ -503,43 +504,26 @@ int bt_mesh_client_clear_list(void *data)
return 0;
}
int bt_mesh_set_client_model_role(bt_mesh_role_param_t *common)
int bt_mesh_set_client_model_role(struct bt_mesh_model *model, u8_t role)
{
bt_mesh_client_user_data_t *client = NULL;
if (!common || !common->model || !common->model->user_data) {
BT_ERR("%s, Invalid parameter", __func__);
if (!model) {
BT_ERR("Invalid client model");
return -EINVAL;
}
client = (bt_mesh_client_user_data_t *)common->model->user_data;
switch (common->role) {
#if CONFIG_BLE_MESH_NODE
case NODE:
/* no matter if provisioner is enabled/disabled , node role can be used to send messages */
client->msg_role = NODE;
break;
#endif
#if CONFIG_BLE_MESH_PROVISIONER
case PROVISIONER:
/* if provisioner is not enabled, provisioner role can't be used to send messages */
if (!bt_mesh_is_provisioner_en()) {
BT_ERR("Provisioner is disabled");
return -EINVAL;
}
client->msg_role = PROVISIONER;
break;
#endif
#if CONFIG_BLE_MESH_FAST_PROV
case FAST_PROV:
client->msg_role = FAST_PROV;
break;
#endif
default:
BT_WARN("Unknown model role 0x%02x", common->role);
client = (bt_mesh_client_user_data_t *)model->user_data;
if (!client) {
BT_ERR("Invalid client user data");
return -EINVAL;
}
if (role >= ROLE_NVAL) {
BT_ERR("Invalid client role 0x%02x", role);
return -EINVAL;
}
client->msg_role = role;
return 0;
}

View File

@ -689,7 +689,6 @@ const struct bt_mesh_model_op gen_property_cli_op[] = {
static int gen_get_state(bt_mesh_client_common_param_t *common, void *value)
{
NET_BUF_SIMPLE_DEFINE(msg, BLE_MESH_GEN_GET_STATE_MSG_LEN);
int err = 0;
bt_mesh_model_msg_init(&msg, common->opcode);
@ -725,14 +724,7 @@ static int gen_get_state(bt_mesh_client_common_param_t *common, void *value)
}
}
err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, &msg,
timeout_handler, common->msg_timeout, true,
common->cb, common->cb_data);
if (err) {
BT_ERR("Failed to send Generic Get message (err %d)", err);
}
return err;
return bt_mesh_client_send_msg(common, &msg, true, timeout_handler);
}
static int gen_set_state(bt_mesh_client_common_param_t *common,
@ -904,21 +896,14 @@ static int gen_set_state(bt_mesh_client_common_param_t *common,
goto end;
}
err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, msg,
timeout_handler, common->msg_timeout, need_ack,
common->cb, common->cb_data);
if (err) {
BT_ERR("Failed to send Generic Set message (err %d)", err);
}
err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler);
end:
bt_mesh_free_buf(msg);
return err;
}
int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common,
void *get, void *status)
int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, void *get)
{
bt_mesh_generic_client_t *client = NULL;
@ -981,8 +966,7 @@ int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common,
return gen_get_state(common, get);
}
int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common,
void *set, void *status)
int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void *set)
{
bt_mesh_generic_client_t *client = NULL;
u16_t length = 0U;

View File

@ -79,6 +79,7 @@ typedef struct {
struct bt_mesh_model *model; /* Pointer to the client model */
struct bt_mesh_msg_ctx ctx; /* Message context */
s32_t msg_timeout; /* Time to get corresponding response */
u8_t msg_role; /* Role (Node/Provisioner) of the device */
const struct bt_mesh_send_cb *cb; /* User defined callback function */
void *cb_data; /* User defined callback value */
} bt_mesh_client_common_param_t;
@ -104,31 +105,23 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(struct bt_mesh_model *
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf, bool need_pub);
int bt_mesh_client_send_msg(struct bt_mesh_model *model,
u32_t opcode,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *msg,
k_work_handler_t timer_handler,
s32_t timeout, bool need_ack,
const struct bt_mesh_send_cb *cb, void *cb_data);
int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param,
struct net_buf_simple *msg, bool need_ack,
k_work_handler_t timer_handler);
int bt_mesh_client_free_node(bt_mesh_client_node_t *node);
int bt_mesh_client_clear_list(void *data);
typedef struct {
struct bt_mesh_model *model; /* The client model structure */
u8_t role; /* Role of the device - Node/Provisioner */
} bt_mesh_role_param_t;
/**
* @brief This function copies node_index for stack internal use.
* @brief Set role of the client model for internal use.
*
* @param[in] common: Pointer to the bt_mesh_role_param_t structure
* @param[in] model: Pointer to the client model
* @param[in] role: Role of the device
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_set_client_model_role(bt_mesh_role_param_t *common);
int bt_mesh_set_client_model_role(struct bt_mesh_model *model, u8_t role);
#ifdef __cplusplus
}

View File

@ -553,24 +553,20 @@ int bt_mesh_gen_property_cli_deinit(struct bt_mesh_model *model, bool primary);
*
* @param[in] common: Message common information structure
* @param[in] get: Pointer of generic get message value
* @param[out] status: Pointer of generic status message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common,
void *get, void *status);
int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, void *get);
/**
* @brief This function is called to set generic states.
*
* @param[in] common: Message common information structure
* @param[in] set: Pointer of generic set message value
* @param[out] status: Pointer of generic status message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common,
void *set, void *status);
int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void *set);
#ifdef __cplusplus
}

View File

@ -523,24 +523,20 @@ int bt_mesh_light_lc_cli_deinit(struct bt_mesh_model *model, bool primary);
*
* @param[in] common: Message common information structure
* @param[in] get: Pointer of light get message value
* @param[out] status: Pointer of light status message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common,
void *get, void *status);
int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, void *get);
/**
* @brief This function is called to set light states.
*
* @param[in] common: Message common information structure
* @param[in] set: Pointer of light set message value
* @param[out] status: Pointer of light status message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common,
void *set, void *status);
int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void *set);
#ifdef __cplusplus
}

View File

@ -158,24 +158,20 @@ int bt_mesh_sensor_cli_deinit(struct bt_mesh_model *model, bool primary);
*
* @param[in] common: Message common information structure
* @param[in] get: Pointer of sensor get message value
* @param[out] status: Pointer of sensor status message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common,
void *get, void *status);
int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, void *get);
/**
* @brief This function is called to set sensor states.
*
* @param[in] common: Message common information structure
* @param[in] set: Pointer of sensor set message value
* @param[out] status: Pointer of sensor status message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common,
void *set, void *status);
int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, void *set);
#ifdef __cplusplus
}

View File

@ -268,24 +268,20 @@ int bt_mesh_scheduler_cli_deinit(struct bt_mesh_model *model, bool primary);
*
* @param[in] common: Message common information structure
* @param[in] get: Pointer of time scene get message value
* @param[out] status: Pointer of time scene status message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common,
void *get, void *status);
int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common, void *get);
/**
* @brief This function is called to set scene states.
*
* @param[in] common: Message common information structure
* @param[in] set: Pointer of time scene set message value
* @param[out] status: Pointer of time scene status message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common,
void *set, void *status);
int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, void *set);
#ifdef __cplusplus
}

View File

@ -772,7 +772,6 @@ const struct bt_mesh_model_op light_lc_cli_op[] = {
static int light_get_state(bt_mesh_client_common_param_t *common, void *value)
{
NET_BUF_SIMPLE_DEFINE(msg, BLE_MESH_LIGHT_GET_STATE_MSG_LEN);
int err = 0;
bt_mesh_model_msg_init(&msg, common->opcode);
@ -790,14 +789,7 @@ static int light_get_state(bt_mesh_client_common_param_t *common, void *value)
}
}
err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, &msg,
timeout_handler, common->msg_timeout, true,
common->cb, common->cb_data);
if (err) {
BT_ERR("Failed to send Lighting Get message (err %d)", err);
}
return err;
return bt_mesh_client_send_msg(common, &msg, true, timeout_handler);
}
static int light_set_state(bt_mesh_client_common_param_t *common,
@ -1028,21 +1020,14 @@ static int light_set_state(bt_mesh_client_common_param_t *common,
goto end;
}
err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, msg,
timeout_handler, common->msg_timeout, need_ack,
common->cb, common->cb_data);
if (err) {
BT_ERR("Failed to send Lighting Set message (err %d)", err);
}
err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler);
end:
bt_mesh_free_buf(msg);
return err;
}
int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common,
void *get, void *status)
int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, void *get)
{
bt_mesh_light_client_t *client = NULL;
@ -1095,8 +1080,7 @@ int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common,
return light_get_state(common, get);
}
int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common,
void *set, void *status)
int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void *set)
{
bt_mesh_light_client_t *client = NULL;
u16_t length = 0U;

View File

@ -447,21 +447,14 @@ static int sensor_act_state(bt_mesh_client_common_param_t *common,
goto end;
}
err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, msg,
timeout_handler, common->msg_timeout, need_ack,
common->cb, common->cb_data);
if (err) {
BT_ERR("Failed to send Sensor client message (err %d)", err);
}
err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler);
end:
bt_mesh_free_buf(msg);
return err;
}
int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common,
void *get, void *status)
int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, void *get)
{
bt_mesh_sensor_client_t *client = NULL;
u16_t length = 0U;
@ -526,8 +519,7 @@ int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common,
return sensor_act_state(common, get, length, true);
}
int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common,
void *set, void *status)
int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, void *set)
{
bt_mesh_sensor_client_t *client = NULL;
u16_t length = 0U;

View File

@ -372,7 +372,6 @@ const struct bt_mesh_model_op scheduler_cli_op[] = {
static int time_scene_get_state(bt_mesh_client_common_param_t *common, void *value)
{
NET_BUF_SIMPLE_DEFINE(msg, BLE_MESH_SCENE_GET_STATE_MSG_LEN);
int err = 0;
bt_mesh_model_msg_init(&msg, common->opcode);
@ -390,14 +389,7 @@ static int time_scene_get_state(bt_mesh_client_common_param_t *common, void *val
}
}
err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, &msg,
timeout_handler, common->msg_timeout, true,
common->cb, common->cb_data);
if (err) {
BT_ERR("Failed to send Time Scene Get message (err %d)", err);
}
return err;
return bt_mesh_client_send_msg(common, &msg, true, timeout_handler);
}
static int time_scene_set_state(bt_mesh_client_common_param_t *common,
@ -485,20 +477,14 @@ static int time_scene_set_state(bt_mesh_client_common_param_t *common,
goto end;
}
err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, msg,
timeout_handler, common->msg_timeout, need_ack,
common->cb, common->cb_data);
if (err) {
BT_ERR("Failed to send Time Scene Set message (err %d)", err);
}
err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler);
end:
bt_mesh_free_buf(msg);
return err;
}
int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common,
void *get, void *status)
int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common, void *get)
{
bt_mesh_time_scene_client_t *client = NULL;
@ -536,8 +522,7 @@ int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common,
return time_scene_get_state(common, get);
}
int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common,
void *set, void *status)
int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, void *set)
{
bt_mesh_time_scene_client_t *client = NULL;
u16_t length = 0U;