ble_mesh: stack: Check client msg result in common func

This commit is contained in:
lly 2020-07-08 09:35:31 +08:00
parent ba38c974e6
commit dfa6332606
7 changed files with 44 additions and 257 deletions

View file

@ -677,48 +677,30 @@ const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = {
static int send_msg_with_none(bt_mesh_client_common_param_t *param, u32_t op)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, op, 0);
int err = 0;
bt_mesh_model_msg_init(&msg, op);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
if (err) {
BT_ERR("%s, send failed (err %d)", __func__, err);
}
return err;
return bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
}
static int send_msg_with_u8(bt_mesh_client_common_param_t *param, u32_t op, u8_t val)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, op, 1);
int err = 0;
bt_mesh_model_msg_init(&msg, op);
net_buf_simple_add_u8(&msg, val);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
if (err) {
BT_ERR("%s, send failed (err %d)", __func__, err);
}
return err;
return bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
}
static int send_msg_with_le16(bt_mesh_client_common_param_t *param, u32_t op, u16_t val)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, op, 2);
int err = 0;
bt_mesh_model_msg_init(&msg, op);
net_buf_simple_add_le16(&msg, val);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_comp_data_get(bt_mesh_client_common_param_t *param, u8_t page)
@ -779,25 +761,18 @@ int bt_mesh_cfg_relay_set(bt_mesh_client_common_param_t *param,
u8_t relay, u8_t retransmit)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_RELAY_SET, 2);
int err = 0;
bt_mesh_model_msg_init(&msg, OP_RELAY_SET);
net_buf_simple_add_u8(&msg, relay);
net_buf_simple_add_u8(&msg, retransmit);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_net_key_add(bt_mesh_client_common_param_t *param,
u16_t net_idx, const u8_t net_key[16])
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_ADD, 18);
int err = 0;
if (!net_key) {
BT_ERR("Invalid NetKey");
@ -808,12 +783,7 @@ int bt_mesh_cfg_net_key_add(bt_mesh_client_common_param_t *param,
net_buf_simple_add_le16(&msg, net_idx);
net_buf_simple_add_mem(&msg, net_key, 16);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_app_key_add(bt_mesh_client_common_param_t *param,
@ -821,7 +791,6 @@ int bt_mesh_cfg_app_key_add(bt_mesh_client_common_param_t *param,
const u8_t app_key[16])
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_ADD, 19);
int err = 0;
if (!app_key) {
BT_ERR("Invalid AppKey");
@ -832,12 +801,7 @@ int bt_mesh_cfg_app_key_add(bt_mesh_client_common_param_t *param,
key_idx_pack(&msg, net_idx, app_idx);
net_buf_simple_add_mem(&msg, app_key, 16);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_mod_app_bind(bt_mesh_client_common_param_t *param,
@ -845,7 +809,6 @@ int bt_mesh_cfg_mod_app_bind(bt_mesh_client_common_param_t *param,
u16_t mod_id, u16_t cid)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_BIND, 8);
int err = 0;
bt_mesh_model_msg_init(&msg, OP_MOD_APP_BIND);
net_buf_simple_add_le16(&msg, elem_addr);
@ -855,12 +818,7 @@ int bt_mesh_cfg_mod_app_bind(bt_mesh_client_common_param_t *param,
}
net_buf_simple_add_le16(&msg, mod_id);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
if (err) {
BT_ERR("%s, send failed (err %d)", __func__, err);
}
return err;
return bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
}
static int mod_sub(bt_mesh_client_common_param_t *param, u32_t op,
@ -868,7 +826,6 @@ static int mod_sub(bt_mesh_client_common_param_t *param, u32_t op,
u16_t mod_id, u16_t cid)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, op, 8);
int err = 0;
bt_mesh_model_msg_init(&msg, op);
net_buf_simple_add_le16(&msg, elem_addr);
@ -878,12 +835,7 @@ static int mod_sub(bt_mesh_client_common_param_t *param, u32_t op,
}
net_buf_simple_add_le16(&msg, mod_id);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_mod_sub_add(bt_mesh_client_common_param_t *param,
@ -912,7 +864,6 @@ static int mod_sub_va(bt_mesh_client_common_param_t *param, u32_t op,
u16_t mod_id, u16_t cid)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, op, 22);
int err = 0;
if (!label) {
BT_ERR("Invalid label uuid");
@ -930,12 +881,7 @@ static int mod_sub_va(bt_mesh_client_common_param_t *param, u32_t op,
}
net_buf_simple_add_le16(&msg, mod_id);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_mod_sub_va_add(bt_mesh_client_common_param_t *param,
@ -963,7 +909,6 @@ 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)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_GET, 6);
int err = 0;
bt_mesh_model_msg_init(&msg, OP_MOD_PUB_GET);
net_buf_simple_add_le16(&msg, elem_addr);
@ -972,12 +917,7 @@ int bt_mesh_cfg_mod_pub_get(bt_mesh_client_common_param_t *param,
}
net_buf_simple_add_le16(&msg, mod_id);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_mod_pub_set(bt_mesh_client_common_param_t *param,
@ -985,7 +925,6 @@ int bt_mesh_cfg_mod_pub_set(bt_mesh_client_common_param_t *param,
struct bt_mesh_cfg_mod_pub *pub)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_SET, 13);
int err = 0;
if (!pub) {
BT_ERR("Invalid model pub set");
@ -1004,19 +943,13 @@ int bt_mesh_cfg_mod_pub_set(bt_mesh_client_common_param_t *param,
}
net_buf_simple_add_le16(&msg, mod_id);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_hb_sub_set(bt_mesh_client_common_param_t *param,
struct bt_mesh_cfg_hb_sub *sub)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_SUB_SET, 5);
int err = 0;
if (!sub) {
BT_ERR("Invalid heartbeat sub set");
@ -1028,12 +961,7 @@ int bt_mesh_cfg_hb_sub_set(bt_mesh_client_common_param_t *param,
net_buf_simple_add_le16(&msg, sub->dst);
net_buf_simple_add_u8(&msg, sub->period);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_hb_sub_get(bt_mesh_client_common_param_t *param)
@ -1045,7 +973,6 @@ int bt_mesh_cfg_hb_pub_set(bt_mesh_client_common_param_t *param,
struct bt_mesh_cfg_hb_pub *pub)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_PUB_SET, 9);
int err = 0;
if (!pub) {
BT_ERR("Invalid heartbeat pub set");
@ -1060,12 +987,7 @@ int bt_mesh_cfg_hb_pub_set(bt_mesh_client_common_param_t *param,
net_buf_simple_add_le16(&msg, pub->feat);
net_buf_simple_add_le16(&msg, pub->net_idx);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_hb_pub_get(bt_mesh_client_common_param_t *param)
@ -1084,7 +1006,6 @@ int bt_mesh_cfg_mod_pub_va_set(bt_mesh_client_common_param_t *param,
struct bt_mesh_cfg_mod_pub *pub)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_VA_SET, 27);
int err = 0;
if (!label || !pub) {
BT_ERR("%s, Invalid parameter", __func__);
@ -1103,19 +1024,13 @@ int bt_mesh_cfg_mod_pub_va_set(bt_mesh_client_common_param_t *param,
}
net_buf_simple_add_le16(&msg, mod_id);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_mod_sub_del_all(bt_mesh_client_common_param_t *param,
u16_t elem_addr, u16_t mod_id, u16_t cid)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_SUB_DEL_ALL, 6);
int err = 0;
bt_mesh_model_msg_init(&msg, OP_MOD_SUB_DEL_ALL);
net_buf_simple_add_le16(&msg, elem_addr);
@ -1124,19 +1039,13 @@ int bt_mesh_cfg_mod_sub_del_all(bt_mesh_client_common_param_t *param,
}
net_buf_simple_add_le16(&msg, mod_id);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
if (err) {
BT_ERR("%s, send failed (err %d)", __func__, err);
}
return err;
return bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
}
static int mod_sub_get(bt_mesh_client_common_param_t *param, u32_t op,
u16_t elem_addr, u16_t mod_id, u16_t cid)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, op, 6);
int err = 0;
bt_mesh_model_msg_init(&msg, op);
net_buf_simple_add_le16(&msg, elem_addr);
@ -1145,12 +1054,7 @@ static int mod_sub_get(bt_mesh_client_common_param_t *param, u32_t op,
}
net_buf_simple_add_le16(&msg, mod_id);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_mod_sub_get(bt_mesh_client_common_param_t *param,
@ -1173,7 +1077,6 @@ int bt_mesh_cfg_net_key_update(bt_mesh_client_common_param_t *param,
u16_t net_idx, const u8_t net_key[16])
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_UPDATE, 18);
int err = 0;
if (!net_key) {
BT_ERR("Invalid NetKey");
@ -1184,12 +1087,7 @@ int bt_mesh_cfg_net_key_update(bt_mesh_client_common_param_t *param,
net_buf_simple_add_le16(&msg, net_idx);
net_buf_simple_add_mem(&msg, net_key, 16);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_net_key_delete(bt_mesh_client_common_param_t *param, u16_t net_idx)
@ -1207,7 +1105,6 @@ int bt_mesh_cfg_app_key_update(bt_mesh_client_common_param_t *param,
const u8_t app_key[16])
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_UPDATE, 19);
int err = 0;
if (!app_key) {
BT_ERR("Invalid AppKey");
@ -1218,29 +1115,18 @@ int bt_mesh_cfg_app_key_update(bt_mesh_client_common_param_t *param,
key_idx_pack(&msg, net_idx, app_idx);
net_buf_simple_add_mem(&msg, app_key, 16);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_app_key_delete(bt_mesh_client_common_param_t *param,
u16_t net_idx, u16_t app_idx)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_DEL, 3);
int err = 0;
bt_mesh_model_msg_init(&msg, OP_APP_KEY_DEL);
key_idx_pack(&msg, net_idx, app_idx);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_app_key_get(bt_mesh_client_common_param_t *param, u16_t net_idx)
@ -1257,7 +1143,6 @@ int bt_mesh_cfg_node_identity_set(bt_mesh_client_common_param_t *param,
u16_t net_idx, u8_t identity)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_IDENTITY_SET, 3);
int err = 0;
if (identity > 0x02) {
BT_ERR("Invalid node identity 0x%02x", identity);
@ -1268,12 +1153,7 @@ int bt_mesh_cfg_node_identity_set(bt_mesh_client_common_param_t *param,
net_buf_simple_add_le16(&msg, net_idx);
net_buf_simple_add_u8(&msg, identity);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_mod_app_unbind(bt_mesh_client_common_param_t *param,
@ -1281,7 +1161,6 @@ int bt_mesh_cfg_mod_app_unbind(bt_mesh_client_common_param_t *param,
u16_t mod_id, u16_t cid)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_UNBIND, 8);
int err = 0;
bt_mesh_model_msg_init(&msg, OP_MOD_APP_UNBIND);
net_buf_simple_add_le16(&msg, elem_addr);
@ -1291,19 +1170,13 @@ int bt_mesh_cfg_mod_app_unbind(bt_mesh_client_common_param_t *param,
}
net_buf_simple_add_le16(&msg, mod_id);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
if (err) {
BT_ERR("%s, send failed (err %d)", __func__, err);
}
return err;
return bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
}
static int mod_app_get(bt_mesh_client_common_param_t *param, u32_t op,
u16_t elem_addr, u16_t mod_id, u16_t cid)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, op, 6);
int err = 0;
bt_mesh_model_msg_init(&msg, op);
net_buf_simple_add_le16(&msg, elem_addr);
@ -1312,12 +1185,7 @@ static int mod_app_get(bt_mesh_client_common_param_t *param, u32_t op,
}
net_buf_simple_add_le16(&msg, mod_id);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_mod_app_get(bt_mesh_client_common_param_t *param,
@ -1345,7 +1213,6 @@ int bt_mesh_cfg_kr_phase_set(bt_mesh_client_common_param_t *param,
u16_t net_idx, u8_t transition)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_KRP_SET, 3);
int err = 0;
if (transition > 0x03) {
BT_ERR("Invalid kr phase transition 0x%02x", transition);
@ -1356,12 +1223,7 @@ int bt_mesh_cfg_kr_phase_set(bt_mesh_client_common_param_t *param,
net_buf_simple_add_le16(&msg, net_idx);
net_buf_simple_add_u8(&msg, transition);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cfg_lpn_timeout_get(bt_mesh_client_common_param_t *param, u16_t lpn_addr)

View file

@ -234,116 +234,74 @@ const struct bt_mesh_model_op bt_mesh_health_cli_op[] = {
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;
bt_mesh_model_msg_init(&msg, OP_ATTENTION_GET);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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(bt_mesh_client_common_param_t *param,
u8_t attention, bool need_ack)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_SET, 1);
int err = 0;
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(param, &msg, need_ack, timeout_handler);
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(bt_mesh_client_common_param_t *param)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_GET, 0);
int err = 0;
bt_mesh_model_msg_init(&msg, OP_HEALTH_PERIOD_GET);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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(bt_mesh_client_common_param_t *param,
u8_t divisor, bool need_ack)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_SET, 1);
int err = 0;
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(param, &msg, need_ack, timeout_handler);
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(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);
int err = 0;
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(param, &msg, need_ack, timeout_handler);
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(bt_mesh_client_common_param_t *param,
u16_t cid, bool need_ack)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_CLEAR, 2);
int err = 0;
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(param, &msg, need_ack, timeout_handler);
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(bt_mesh_client_common_param_t *param, u16_t cid)
{
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_GET, 2);
int err = 0;
bt_mesh_model_msg_init(&msg, OP_HEALTH_FAULT_GET);
net_buf_simple_add_le16(&msg, cid);
err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler);
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_cli_init(struct bt_mesh_model *model, bool primary)

View file

@ -287,18 +287,18 @@ int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param,
return -EIO;
}
if (!need_ack) {
/* If this is an unack message, send it directly. */
return bt_mesh_model_send(param->model, &param->ctx, msg, param->cb, param->cb_data);
}
if (!BLE_MESH_ADDR_IS_UNICAST(param->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(param->model, &param->ctx, msg, param->cb, param->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) {

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,12 +724,7 @@ static int gen_get_state(bt_mesh_client_common_param_t *common, void *value)
}
}
err = bt_mesh_client_send_msg(common, &msg, true, timeout_handler);
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,
@ -903,13 +897,9 @@ static int gen_set_state(bt_mesh_client_common_param_t *common,
}
err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler);
if (err) {
BT_ERR("Failed to send Generic Set message (err %d)", err);
}
end:
bt_mesh_free_buf(msg);
return err;
}

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,12 +789,7 @@ static int light_get_state(bt_mesh_client_common_param_t *common, void *value)
}
}
err = bt_mesh_client_send_msg(common, &msg, true, timeout_handler);
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,
@ -1027,13 +1021,9 @@ static int light_set_state(bt_mesh_client_common_param_t *common,
}
err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler);
if (err) {
BT_ERR("Failed to send Lighting Set message (err %d)", err);
}
end:
bt_mesh_free_buf(msg);
return err;
}

View file

@ -448,13 +448,9 @@ static int sensor_act_state(bt_mesh_client_common_param_t *common,
}
err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler);
if (err) {
BT_ERR("Failed to send Sensor client message (err %d)", err);
}
end:
bt_mesh_free_buf(msg);
return err;
}

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,12 +389,7 @@ static int time_scene_get_state(bt_mesh_client_common_param_t *common, void *val
}
}
err = bt_mesh_client_send_msg(common, &msg, true, timeout_handler);
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,
@ -484,9 +478,6 @@ static int time_scene_set_state(bt_mesh_client_common_param_t *common,
}
err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler);
if (err) {
BT_ERR("Failed to send Time Scene Set message (err %d)", err);
}
end:
bt_mesh_free_buf(msg);