diff --git a/include/bluetooth/mesh/access.h b/include/bluetooth/mesh/access.h index d46a59cd255..fd7c7a4abe8 100644 --- a/include/bluetooth/mesh/access.h +++ b/include/bluetooth/mesh/access.h @@ -175,10 +175,12 @@ struct bt_mesh_model_op { * @param ctx Message context for the message. * @param buf Message buffer containing the message payload, not * including the opcode. + * + * @return Zero on success or (negative) error code otherwise. */ - void (*const func)(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf); + int (*const func)(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf); }; #define BT_MESH_MODEL_OP_1(b0) (b0) diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 1453820c114..f71292d06d1 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -670,7 +670,7 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) * receive the message. */ net_buf_simple_save(buf, &state); - op->func(model, &rx->ctx, buf); + (void)op->func(model, &rx->ctx, buf); net_buf_simple_restore(buf, &state); } } diff --git a/subsys/bluetooth/mesh/cfg_cli.c b/subsys/bluetooth/mesh/cfg_cli.c index bac5aedd69a..3a0b9db74e1 100644 --- a/subsys/bluetooth/mesh/cfg_cli.c +++ b/subsys/bluetooth/mesh/cfg_cli.c @@ -38,9 +38,9 @@ static int32_t msg_timeout; static struct bt_mesh_cfg_cli *cli; -static void comp_data_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int comp_data_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct comp_data *param; size_t to_copy; @@ -51,7 +51,7 @@ static void comp_data_status(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_DEV_COMP_DATA_STATUS, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } if (param->page) { @@ -62,12 +62,14 @@ static void comp_data_status(struct bt_mesh_model *model, net_buf_simple_add_mem(param->comp, buf->data, to_copy); bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } -static void state_status_u8(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf, - uint32_t expect_status) +static int state_status_u8(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf, + uint32_t expect_status) { uint8_t *status; @@ -77,40 +79,42 @@ static void state_status_u8(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, expect_status, ctx->addr, (void **)&status)) { - return; + return -ENOENT; } *status = net_buf_simple_pull_u8(buf); bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } -static void beacon_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int beacon_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { - state_status_u8(model, ctx, buf, OP_BEACON_STATUS); + return state_status_u8(model, ctx, buf, OP_BEACON_STATUS); } -static void ttl_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int ttl_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { - state_status_u8(model, ctx, buf, OP_DEFAULT_TTL_STATUS); + return state_status_u8(model, ctx, buf, OP_DEFAULT_TTL_STATUS); } -static void friend_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int friend_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { - state_status_u8(model, ctx, buf, OP_FRIEND_STATUS); + return state_status_u8(model, ctx, buf, OP_FRIEND_STATUS); } -static void gatt_proxy_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int gatt_proxy_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { - state_status_u8(model, ctx, buf, OP_GATT_PROXY_STATUS); + return state_status_u8(model, ctx, buf, OP_GATT_PROXY_STATUS); } struct relay_param { @@ -118,9 +122,9 @@ struct relay_param { uint8_t *transmit; }; -static void relay_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int relay_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct relay_param *param; @@ -130,18 +134,20 @@ static void relay_status(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_RELAY_STATUS, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } *param->status = net_buf_simple_pull_u8(buf); *param->transmit = net_buf_simple_pull_u8(buf); bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } -static void net_transmit_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int net_transmit_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint8_t *status; @@ -151,12 +157,14 @@ static void net_transmit_status(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_NET_TRANSMIT_STATUS, ctx->addr, (void **)&status)) { - return; + return -ENOENT; } *status = net_buf_simple_pull_u8(buf); bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } struct net_key_param { @@ -164,9 +172,9 @@ struct net_key_param { uint16_t net_idx; }; -static void net_key_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int net_key_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct net_key_param *param; uint16_t net_idx; @@ -178,7 +186,7 @@ static void net_key_status(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_NET_KEY_STATUS, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } status = net_buf_simple_pull_u8(buf); @@ -186,7 +194,7 @@ static void net_key_status(struct bt_mesh_model *model, if (param->net_idx != net_idx) { BT_WARN("Net Key Status key index does not match"); - return; + return -ENOENT; } if (param->status) { @@ -194,6 +202,8 @@ static void net_key_status(struct bt_mesh_model *model, } bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } struct net_key_list_param { @@ -201,9 +211,9 @@ struct net_key_list_param { size_t *key_cnt; }; -static void net_key_list(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int net_key_list(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct net_key_list_param *param; int i; @@ -214,7 +224,7 @@ static void net_key_list(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_NET_KEY_LIST, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } for (i = 0; i < *param->key_cnt && buf->len >= 3; i += 2) { @@ -228,10 +238,13 @@ static void net_key_list(struct bt_mesh_model *model, *param->key_cnt = i; bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } -static void node_reset_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) +static int node_reset_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { bool *param = NULL; BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x", @@ -239,13 +252,15 @@ static void node_reset_status(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_NODE_RESET_STATUS, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } if (param) { *param = true; } bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } struct app_key_param { @@ -254,9 +269,9 @@ struct app_key_param { uint16_t app_idx; }; -static void app_key_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int app_key_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct app_key_param *param; uint16_t net_idx, app_idx; @@ -268,7 +283,7 @@ static void app_key_status(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_APP_KEY_STATUS, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } status = net_buf_simple_pull_u8(buf); @@ -276,7 +291,7 @@ static void app_key_status(struct bt_mesh_model *model, if (param->net_idx != net_idx || param->app_idx != app_idx) { BT_WARN("App Key Status key indices did not match"); - return; + return -ENOENT; } if (param->status) { @@ -284,6 +299,8 @@ static void app_key_status(struct bt_mesh_model *model, } bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } struct app_key_list_param { @@ -293,9 +310,9 @@ struct app_key_list_param { size_t *key_cnt; }; -static void app_key_list(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int app_key_list(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct app_key_list_param *param; uint16_t net_idx; @@ -308,7 +325,7 @@ static void app_key_list(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_APP_KEY_LIST, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } status = net_buf_simple_pull_u8(buf); @@ -316,7 +333,7 @@ static void app_key_list(struct bt_mesh_model *model, if (param->net_idx != net_idx) { BT_WARN("App Key List Net Key index did not match"); - return; + return -ENOENT; } for (i = 0; i < *param->key_cnt && buf->len >= 3; i += 2) { @@ -333,6 +350,8 @@ static void app_key_list(struct bt_mesh_model *model, } bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } struct mod_app_param { @@ -343,9 +362,9 @@ struct mod_app_param { uint16_t cid; }; -static void mod_app_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_app_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint16_t elem_addr, mod_app_idx, mod_id, cid; struct mod_app_param *param; @@ -357,7 +376,7 @@ static void mod_app_status(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_MOD_APP_STATUS, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } status = net_buf_simple_pull_u8(buf); @@ -376,7 +395,7 @@ static void mod_app_status(struct bt_mesh_model *model, param->mod_app_idx != mod_app_idx || param->mod_id != mod_id || param->cid != cid) { BT_WARN("Model App Status parameters did not match"); - return; + return -ENOENT; } if (param->status) { @@ -384,6 +403,8 @@ static void mod_app_status(struct bt_mesh_model *model, } bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } struct mod_member_list_param { @@ -395,9 +416,9 @@ struct mod_member_list_param { size_t *member_cnt; }; -static void mod_member_list_handle(struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf, bool vnd, - struct mod_member_list_param *param) +static int mod_member_list_handle(struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf, bool vnd, + struct mod_member_list_param *param) { uint16_t elem_addr, mod_id, cid; uint8_t status; @@ -414,12 +435,12 @@ static void mod_member_list_handle(struct bt_mesh_msg_ctx *ctx, if (param->elem_addr != elem_addr || param->mod_id != mod_id || (vnd && param->cid != cid)) { BT_WARN("Model Member List parameters did not match"); - return; + return -ENOENT; } if (buf->len % 2) { BT_WARN("Model Member List invalid length"); - return; + return -EINVAL; } for (i = 0; i < *param->member_cnt && buf->len; i++) { @@ -432,11 +453,13 @@ static void mod_member_list_handle(struct bt_mesh_msg_ctx *ctx, } bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } -static void mod_app_list(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_app_list(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct mod_member_list_param *param; @@ -446,15 +469,15 @@ static void mod_app_list(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_SIG_MOD_APP_LIST, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } - mod_member_list_handle(ctx, buf, false, param); + return mod_member_list_handle(ctx, buf, false, param); } -static void mod_app_list_vnd(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_app_list_vnd(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct mod_member_list_param *param; @@ -464,10 +487,10 @@ static void mod_app_list_vnd(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_VND_MOD_APP_LIST, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } - mod_member_list_handle(ctx, buf, true, param); + return mod_member_list_handle(ctx, buf, true, param); } struct mod_pub_param { @@ -478,7 +501,7 @@ struct mod_pub_param { struct bt_mesh_cfg_mod_pub *pub; }; -static void mod_pub_status(struct bt_mesh_model *model, +static int mod_pub_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { @@ -492,13 +515,13 @@ static void mod_pub_status(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_MOD_PUB_STATUS, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } if (param->cid != CID_NVAL) { if (buf->len < 14) { BT_WARN("Unexpected Mod Pub Status with SIG Model"); - return; + return -ENOENT; } cid = sys_get_le16(&buf->data[10]); @@ -506,7 +529,7 @@ static void mod_pub_status(struct bt_mesh_model *model, } else { if (buf->len > 12) { BT_WARN("Unexpected Mod Pub Status with Vendor Model"); - return; + return -ENOENT; } cid = CID_NVAL; @@ -515,7 +538,7 @@ static void mod_pub_status(struct bt_mesh_model *model, if (mod_id != param->mod_id || cid != param->cid) { BT_WARN("Mod Pub Model ID or Company ID mismatch"); - return; + return -ENOENT; } status = net_buf_simple_pull_u8(buf); @@ -524,7 +547,7 @@ static void mod_pub_status(struct bt_mesh_model *model, if (elem_addr != param->elem_addr) { BT_WARN("Model Pub Status for unexpected element (0x%04x)", elem_addr); - return; + return -ENOENT; } if (param->status) { @@ -542,6 +565,8 @@ static void mod_pub_status(struct bt_mesh_model *model, } bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } struct mod_sub_param { @@ -553,9 +578,9 @@ struct mod_sub_param { uint16_t cid; }; -static void mod_sub_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_sub_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint16_t elem_addr, sub_addr, mod_id, cid; struct mod_sub_param *param; @@ -567,7 +592,7 @@ static void mod_sub_status(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_MOD_SUB_STATUS, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } status = net_buf_simple_pull_u8(buf); @@ -586,7 +611,7 @@ static void mod_sub_status(struct bt_mesh_model *model, (param->expect_sub && *param->expect_sub != sub_addr) || param->cid != cid) { BT_WARN("Model Subscription Status parameters did not match"); - return; + return -ENOENT; } if (param->sub_addr) { @@ -598,11 +623,13 @@ static void mod_sub_status(struct bt_mesh_model *model, } bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } -static void mod_sub_list(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_sub_list(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct mod_member_list_param *param; @@ -612,15 +639,15 @@ static void mod_sub_list(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_MOD_SUB_LIST, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } - mod_member_list_handle(ctx, buf, false, param); + return mod_member_list_handle(ctx, buf, false, param); } -static void mod_sub_list_vnd(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_sub_list_vnd(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct mod_member_list_param *param; @@ -630,10 +657,10 @@ static void mod_sub_list_vnd(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_MOD_SUB_LIST_VND, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } - mod_member_list_handle(ctx, buf, true, param); + return mod_member_list_handle(ctx, buf, true, param); } struct hb_sub_param { @@ -641,9 +668,9 @@ struct hb_sub_param { struct bt_mesh_cfg_hb_sub *sub; }; -static void hb_sub_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int hb_sub_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct hb_sub_param *param; @@ -653,7 +680,7 @@ static void hb_sub_status(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_HEARTBEAT_SUB_STATUS, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } *param->status = net_buf_simple_pull_u8(buf); @@ -666,6 +693,8 @@ static void hb_sub_status(struct bt_mesh_model *model, param->sub->max = net_buf_simple_pull_u8(buf); bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } struct hb_pub_param { @@ -673,9 +702,9 @@ struct hb_pub_param { struct bt_mesh_cfg_hb_pub *pub; }; -static void hb_pub_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int hb_pub_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct hb_pub_param *param; @@ -685,7 +714,7 @@ static void hb_pub_status(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_HEARTBEAT_PUB_STATUS, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } *param->status = net_buf_simple_pull_u8(buf); @@ -700,6 +729,8 @@ static void hb_pub_status(struct bt_mesh_model *model, } bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + + return 0; } const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = { diff --git a/subsys/bluetooth/mesh/cfg_srv.c b/subsys/bluetooth/mesh/cfg_srv.c index e98b5dbef8e..b468f8f0930 100644 --- a/subsys/bluetooth/mesh/cfg_srv.c +++ b/subsys/bluetooth/mesh/cfg_srv.c @@ -111,12 +111,13 @@ static int comp_get_page_0(struct net_buf_simple *buf) return 0; } -static void dev_comp_data_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int dev_comp_data_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { NET_BUF_SIMPLE_DEFINE(sdu, BT_MESH_TX_SDU_MAX); uint8_t page; + int err; BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s", ctx->net_idx, ctx->app_idx, ctx->addr, buf->len, @@ -131,14 +132,17 @@ static void dev_comp_data_get(struct bt_mesh_model *model, bt_mesh_model_msg_init(&sdu, OP_DEV_COMP_DATA_STATUS); net_buf_simple_add_u8(&sdu, page); - if (comp_get_page_0(&sdu) < 0) { + err = comp_get_page_0(&sdu); + if (err) { BT_ERR("Unable to get composition page 0"); - return; + return err; } if (bt_mesh_model_send(model, ctx, &sdu, NULL, NULL)) { BT_ERR("Unable to send Device Composition Status response"); } + + return err; } static struct bt_mesh_model *get_model(struct bt_mesh_elem *elem, @@ -319,10 +323,10 @@ static uint8_t mod_unbind(struct bt_mesh_model *model, uint16_t key_idx, bool st return STATUS_SUCCESS; } -static void send_app_key_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - uint8_t status, - uint16_t app_idx, uint16_t net_idx) +static int send_app_key_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + uint8_t status, + uint16_t app_idx, uint16_t net_idx) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_STATUS, 4); @@ -333,11 +337,13 @@ static void send_app_key_status(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send App Key Status response"); } + + return 0; } -static void app_key_add(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int app_key_add(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint16_t key_net_idx, key_app_idx; uint8_t status; @@ -348,12 +354,12 @@ static void app_key_add(struct bt_mesh_model *model, status = bt_mesh_app_key_add(key_app_idx, key_net_idx, buf->data); - send_app_key_status(model, ctx, status, key_app_idx, key_net_idx); + return send_app_key_status(model, ctx, status, key_app_idx, key_net_idx); } -static void app_key_update(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int app_key_update(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint16_t key_net_idx, key_app_idx; uint8_t status; @@ -365,7 +371,7 @@ static void app_key_update(struct bt_mesh_model *model, status = bt_mesh_app_key_update(key_app_idx, key_net_idx, buf->data); BT_DBG("status 0x%02x", status); - send_app_key_status(model, ctx, status, key_app_idx, key_net_idx); + return send_app_key_status(model, ctx, status, key_app_idx, key_net_idx); } static void mod_app_key_del(struct bt_mesh_model *mod, @@ -387,9 +393,9 @@ static void app_key_evt(uint16_t app_idx, uint16_t net_idx, BT_MESH_APP_KEY_CB_DEFINE(app_key_evt); -static void app_key_del(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int app_key_del(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint16_t key_net_idx, key_app_idx; uint8_t status; @@ -400,15 +406,15 @@ static void app_key_del(struct bt_mesh_model *model, status = bt_mesh_app_key_del(key_app_idx, key_net_idx); - send_app_key_status(model, ctx, status, key_app_idx, key_net_idx); + return send_app_key_status(model, ctx, status, key_app_idx, key_net_idx); } /* Index list length: 3 bytes for every pair and 2 bytes for an odd idx */ #define IDX_LEN(num) (((num) / 2) * 3 + ((num) % 2) * 2) -static void app_key_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int app_key_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_LIST, 3 + IDX_LEN(CONFIG_BT_MESH_APP_KEY_COUNT)); @@ -421,7 +427,7 @@ static void app_key_get(struct bt_mesh_model *model, get_idx = net_buf_simple_pull_le16(buf); if (get_idx > 0xfff) { BT_ERR("Invalid NetKeyIndex 0x%04x", get_idx); - return; + return -EINVAL; } BT_DBG("idx 0x%04x", get_idx); @@ -458,11 +464,13 @@ send_status: if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send AppKey List"); } + + return 0; } -static void beacon_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int beacon_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_BEACON_STATUS, 1); @@ -476,11 +484,13 @@ static void beacon_get(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Config Beacon Status response"); } + + return 0; } -static void beacon_set(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int beacon_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_BEACON_STATUS, 1); @@ -490,7 +500,7 @@ static void beacon_set(struct bt_mesh_model *model, if (buf->data[0] != 0x00 && buf->data[0] != 0x01) { BT_WARN("Invalid Config Beacon value 0x%02x", buf->data[0]); - return; + return -EINVAL; } bt_mesh_beacon_set(buf->data[0]); @@ -501,11 +511,13 @@ static void beacon_set(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Config Beacon Status response"); } + + return 0; } -static void default_ttl_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int default_ttl_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_DEFAULT_TTL_STATUS, 1); @@ -519,11 +531,13 @@ static void default_ttl_get(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Default TTL Status response"); } + + return 0; } -static void default_ttl_set(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int default_ttl_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_DEFAULT_TTL_STATUS, 1); int err; @@ -535,7 +549,7 @@ static void default_ttl_set(struct bt_mesh_model *model, err = bt_mesh_default_ttl_set(buf->data[0]); if (err) { BT_WARN("Prohibited Default TTL value 0x%02x", buf->data[0]); - return; + return err; } bt_mesh_model_msg_init(&msg, OP_DEFAULT_TTL_STATUS); @@ -544,10 +558,12 @@ static void default_ttl_set(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Default TTL Status response"); } + + return 0; } -static void send_gatt_proxy_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx) +static int send_gatt_proxy_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_GATT_PROXY_STATUS, 1); @@ -557,22 +573,24 @@ static void send_gatt_proxy_status(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send GATT Proxy Status"); } + + return 0; } -static void gatt_proxy_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int gatt_proxy_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s", ctx->net_idx, ctx->app_idx, ctx->addr, buf->len, bt_hex(buf->data, buf->len)); - send_gatt_proxy_status(model, ctx); + return send_gatt_proxy_status(model, ctx); } -static void gatt_proxy_set(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int gatt_proxy_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s", ctx->net_idx, ctx->app_idx, ctx->addr, buf->len, @@ -580,17 +598,17 @@ static void gatt_proxy_set(struct bt_mesh_model *model, if (buf->data[0] != 0x00 && buf->data[0] != 0x01) { BT_WARN("Invalid GATT Proxy value 0x%02x", buf->data[0]); - return; + return -EINVAL; } (void)bt_mesh_gatt_proxy_set(buf->data[0]); - send_gatt_proxy_status(model, ctx); + return send_gatt_proxy_status(model, ctx); } -static void net_transmit_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int net_transmit_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_NET_TRANSMIT_STATUS, 1); @@ -604,11 +622,13 @@ static void net_transmit_get(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Config Network Transmit Status"); } + + return 0; } -static void net_transmit_set(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int net_transmit_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_NET_TRANSMIT_STATUS, 1); @@ -628,11 +648,13 @@ static void net_transmit_set(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Network Transmit Status"); } + + return 0; } -static void relay_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int relay_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_RELAY_STATUS, 2); @@ -647,11 +669,13 @@ static void relay_get(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Config Relay Status response"); } + + return 0; } -static void relay_set(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int relay_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_RELAY_STATUS, 2); @@ -661,7 +685,7 @@ static void relay_set(struct bt_mesh_model *model, if (buf->data[0] != 0x00 && buf->data[0] != 0x01) { BT_WARN("Invalid Relay value 0x%02x", buf->data[0]); - return; + return -EINVAL; } (void)bt_mesh_relay_set(buf->data[0], buf->data[1]); @@ -673,13 +697,15 @@ static void relay_set(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Relay Status response"); } + + return 0; } -static void send_mod_pub_status(struct bt_mesh_model *cfg_mod, - struct bt_mesh_msg_ctx *ctx, - uint16_t elem_addr, uint16_t pub_addr, - bool vnd, struct bt_mesh_model *mod, - uint8_t status, uint8_t *mod_id) +static int send_mod_pub_status(struct bt_mesh_model *cfg_mod, + struct bt_mesh_msg_ctx *ctx, uint16_t elem_addr, + uint16_t pub_addr, bool vnd, + struct bt_mesh_model *mod, uint8_t status, + uint8_t *mod_id) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_STATUS, 14); @@ -711,11 +737,12 @@ static void send_mod_pub_status(struct bt_mesh_model *cfg_mod, if (bt_mesh_model_send(cfg_mod, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Model Publication Status"); } + + return 0; } -static void mod_pub_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_pub_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint16_t elem_addr, pub_addr = 0U; struct bt_mesh_model *mod; @@ -726,7 +753,7 @@ static void mod_pub_get(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } mod_id = buf->data; @@ -756,13 +783,13 @@ static void mod_pub_get(struct bt_mesh_model *model, status = STATUS_SUCCESS; send_status: - send_mod_pub_status(model, ctx, elem_addr, pub_addr, vnd, mod, - status, mod_id); + return send_mod_pub_status(model, ctx, elem_addr, pub_addr, vnd, mod, + status, mod_id); } -static void mod_pub_set(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_pub_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint8_t retransmit, status, pub_ttl, pub_period, cred_flag; uint16_t elem_addr, pub_addr, pub_app_idx; @@ -774,7 +801,7 @@ static void mod_pub_set(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } pub_addr = net_buf_simple_pull_le16(buf); @@ -785,7 +812,7 @@ static void mod_pub_set(struct bt_mesh_model *model, pub_ttl = net_buf_simple_pull_u8(buf); if (pub_ttl > BT_MESH_TTL_MAX && pub_ttl != BT_MESH_TTL_DEFAULT) { BT_ERR("Invalid TTL value 0x%02x", pub_ttl); - return; + return -EINVAL; } pub_period = net_buf_simple_pull_u8(buf); @@ -818,8 +845,8 @@ static void mod_pub_set(struct bt_mesh_model *model, pub_period, retransmit, true); send_status: - send_mod_pub_status(model, ctx, elem_addr, pub_addr, vnd, mod, - status, mod_id); + return send_mod_pub_status(model, ctx, elem_addr, pub_addr, vnd, mod, + status, mod_id); } static size_t mod_sub_list_clear(struct bt_mesh_model *mod) @@ -854,9 +881,9 @@ static size_t mod_sub_list_clear(struct bt_mesh_model *mod) return clear_count; } -static void mod_pub_va_set(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_pub_va_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint8_t retransmit, status, pub_ttl, pub_period, cred_flag; uint16_t elem_addr, pub_addr, pub_app_idx; @@ -869,7 +896,7 @@ static void mod_pub_va_set(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } label_uuid = net_buf_simple_pull_mem(buf, 16); @@ -879,7 +906,7 @@ static void mod_pub_va_set(struct bt_mesh_model *model, pub_ttl = net_buf_simple_pull_u8(buf); if (pub_ttl > BT_MESH_TTL_MAX && pub_ttl != BT_MESH_TTL_DEFAULT) { BT_ERR("Invalid TTL value 0x%02x", pub_ttl); - return; + return -EINVAL; } pub_period = net_buf_simple_pull_u8(buf); @@ -921,14 +948,14 @@ static void mod_pub_va_set(struct bt_mesh_model *model, } send_status: - send_mod_pub_status(model, ctx, elem_addr, pub_addr, vnd, mod, - status, mod_id); + return send_mod_pub_status(model, ctx, elem_addr, pub_addr, vnd, mod, + status, mod_id); } -static void send_mod_sub_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, uint8_t status, - uint16_t elem_addr, uint16_t sub_addr, uint8_t *mod_id, - bool vnd) +static int send_mod_sub_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, uint8_t status, + uint16_t elem_addr, uint16_t sub_addr, uint8_t *mod_id, + bool vnd) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_SUB_STATUS, 9); @@ -950,11 +977,13 @@ static void send_mod_sub_status(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Model Subscription Status"); } + + return 0; } -static void mod_sub_add(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_sub_add(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint16_t elem_addr, sub_addr; struct bt_mesh_model *mod; @@ -967,7 +996,7 @@ static void mod_sub_add(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } sub_addr = net_buf_simple_pull_le16(buf); @@ -1021,13 +1050,13 @@ static void mod_sub_add(struct bt_mesh_model *model, send_status: - send_mod_sub_status(model, ctx, status, elem_addr, sub_addr, - mod_id, vnd); + return send_mod_sub_status(model, ctx, status, elem_addr, sub_addr, + mod_id, vnd); } -static void mod_sub_del(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_sub_del(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint16_t elem_addr, sub_addr; struct bt_mesh_model *mod; @@ -1040,7 +1069,7 @@ static void mod_sub_del(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } sub_addr = net_buf_simple_pull_le16(buf); @@ -1087,8 +1116,8 @@ static void mod_sub_del(struct bt_mesh_model *model, } send_status: - send_mod_sub_status(model, ctx, status, elem_addr, sub_addr, - mod_id, vnd); + return send_mod_sub_status(model, ctx, status, elem_addr, sub_addr, + mod_id, vnd); } static enum bt_mesh_walk mod_sub_clear_visitor(struct bt_mesh_model *mod, @@ -1103,9 +1132,9 @@ static enum bt_mesh_walk mod_sub_clear_visitor(struct bt_mesh_model *mod, return BT_MESH_WALK_CONTINUE; } -static void mod_sub_overwrite(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_sub_overwrite(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint16_t elem_addr, sub_addr; struct bt_mesh_model *mod; @@ -1117,7 +1146,7 @@ static void mod_sub_overwrite(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } sub_addr = net_buf_simple_pull_le16(buf); @@ -1166,13 +1195,13 @@ static void mod_sub_overwrite(struct bt_mesh_model *model, send_status: - send_mod_sub_status(model, ctx, status, elem_addr, sub_addr, - mod_id, vnd); + return send_mod_sub_status(model, ctx, status, elem_addr, sub_addr, + mod_id, vnd); } -static void mod_sub_del_all(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_sub_del_all(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct bt_mesh_model *mod; struct bt_mesh_elem *elem; @@ -1184,7 +1213,7 @@ static void mod_sub_del_all(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } BT_DBG("elem_addr 0x%04x", elem_addr); @@ -1215,8 +1244,8 @@ static void mod_sub_del_all(struct bt_mesh_model *model, status = STATUS_SUCCESS; send_status: - send_mod_sub_status(model, ctx, status, elem_addr, - BT_MESH_ADDR_UNASSIGNED, mod_id, vnd); + return send_mod_sub_status(model, ctx, status, elem_addr, + BT_MESH_ADDR_UNASSIGNED, mod_id, vnd); } struct mod_sub_list_ctx { @@ -1256,9 +1285,9 @@ static enum bt_mesh_walk mod_sub_list_visitor(struct bt_mesh_model *mod, return BT_MESH_WALK_CONTINUE; } -static void mod_sub_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_sub_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { NET_BUF_SIMPLE_DEFINE(msg, BT_MESH_TX_SDU_MAX); struct mod_sub_list_ctx visit_ctx; @@ -1269,7 +1298,7 @@ static void mod_sub_get(struct bt_mesh_model *model, addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } id = net_buf_simple_pull_le16(buf); @@ -1308,11 +1337,13 @@ send_list: if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Model Subscription List"); } + + return 0; } -static void mod_sub_get_vnd(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_sub_get_vnd(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { NET_BUF_SIMPLE_DEFINE(msg, BT_MESH_TX_SDU_MAX); struct mod_sub_list_ctx visit_ctx; @@ -1323,7 +1354,7 @@ static void mod_sub_get_vnd(struct bt_mesh_model *model, addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } company = net_buf_simple_pull_le16(buf); @@ -1366,11 +1397,13 @@ send_list: if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Vendor Model Subscription List"); } + + return 0; } -static void mod_sub_va_add(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_sub_va_add(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint16_t elem_addr, sub_addr; struct bt_mesh_model *mod; @@ -1384,7 +1417,7 @@ static void mod_sub_va_add(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } label_uuid = net_buf_simple_pull_mem(buf, 16); @@ -1441,13 +1474,13 @@ static void mod_sub_va_add(struct bt_mesh_model *model, status = STATUS_SUCCESS; send_status: - send_mod_sub_status(model, ctx, status, elem_addr, sub_addr, - mod_id, vnd); + return send_mod_sub_status(model, ctx, status, elem_addr, sub_addr, + mod_id, vnd); } -static void mod_sub_va_del(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_sub_va_del(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint16_t elem_addr, sub_addr; struct bt_mesh_model *mod; @@ -1461,7 +1494,7 @@ static void mod_sub_va_del(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } label_uuid = net_buf_simple_pull_mem(buf, 16); @@ -1509,13 +1542,13 @@ static void mod_sub_va_del(struct bt_mesh_model *model, } send_status: - send_mod_sub_status(model, ctx, status, elem_addr, sub_addr, - mod_id, vnd); + return send_mod_sub_status(model, ctx, status, elem_addr, sub_addr, + mod_id, vnd); } -static void mod_sub_va_overwrite(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_sub_va_overwrite(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint16_t elem_addr, sub_addr = BT_MESH_ADDR_UNASSIGNED; struct bt_mesh_model *mod; @@ -1528,7 +1561,7 @@ static void mod_sub_va_overwrite(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } label_uuid = net_buf_simple_pull_mem(buf, 16); @@ -1573,13 +1606,13 @@ static void mod_sub_va_overwrite(struct bt_mesh_model *model, } send_status: - send_mod_sub_status(model, ctx, status, elem_addr, sub_addr, - mod_id, vnd); + return send_mod_sub_status(model, ctx, status, elem_addr, sub_addr, + mod_id, vnd); } -static void send_net_key_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - uint16_t idx, uint8_t status) +static int send_net_key_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, uint16_t idx, + uint8_t status) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_STATUS, 3); @@ -1591,11 +1624,12 @@ static void send_net_key_status(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send NetKey Status"); } + + return 0; } -static void net_key_add(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int net_key_add(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint8_t status; uint16_t idx; @@ -1603,19 +1637,19 @@ static void net_key_add(struct bt_mesh_model *model, idx = net_buf_simple_pull_le16(buf); if (idx > 0xfff) { BT_ERR("Invalid NetKeyIndex 0x%04x", idx); - return; + return -EINVAL; } BT_DBG("idx 0x%04x", idx); status = bt_mesh_subnet_add(idx, buf->data); - send_net_key_status(model, ctx, idx, status); + return send_net_key_status(model, ctx, idx, status); } -static void net_key_update(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int net_key_update(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint8_t status; uint16_t idx; @@ -1623,24 +1657,24 @@ static void net_key_update(struct bt_mesh_model *model, idx = net_buf_simple_pull_le16(buf); if (idx > 0xfff) { BT_ERR("Invalid NetKeyIndex 0x%04x", idx); - return; + return -EINVAL; } status = bt_mesh_subnet_update(idx, buf->data); - send_net_key_status(model, ctx, idx, status); + return send_net_key_status(model, ctx, idx, status); } -static void net_key_del(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int net_key_del(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint16_t del_idx; del_idx = net_buf_simple_pull_le16(buf); if (del_idx > 0xfff) { BT_ERR("Invalid NetKeyIndex 0x%04x", del_idx); - return; + return -EINVAL; } BT_DBG("idx 0x%04x", del_idx); @@ -1649,19 +1683,18 @@ static void net_key_del(struct bt_mesh_model *model, * The NetKey List must contain a minimum of one NetKey. */ if (ctx->net_idx == del_idx) { - send_net_key_status(model, ctx, del_idx, - STATUS_CANNOT_REMOVE); - return; + return send_net_key_status(model, ctx, del_idx, + STATUS_CANNOT_REMOVE); } - bt_mesh_subnet_del(del_idx); + (void)bt_mesh_subnet_del(del_idx); - send_net_key_status(model, ctx, del_idx, STATUS_SUCCESS); + return send_net_key_status(model, ctx, del_idx, STATUS_SUCCESS); } -static void net_key_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int net_key_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_LIST, IDX_LEN(CONFIG_BT_MESH_SUBNET_COUNT)); @@ -1687,12 +1720,14 @@ static void net_key_get(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send NetKey List"); } + + return 0; } -static void send_node_id_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - uint8_t status, - uint16_t net_idx, uint8_t node_id) +static int send_node_id_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + uint8_t status, + uint16_t net_idx, uint8_t node_id) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_IDENTITY_STATUS, 4); @@ -1704,11 +1739,13 @@ static void send_node_id_status(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Node Identity Status"); } + + return 0; } -static void node_identity_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int node_identity_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { enum bt_mesh_feat_state node_id; uint8_t status; @@ -1721,17 +1758,17 @@ static void node_identity_get(struct bt_mesh_model *model, idx = net_buf_simple_pull_le16(buf); if (idx > 0xfff) { BT_ERR("Invalid NetKeyIndex 0x%04x", idx); - return; + return -EINVAL; } status = bt_mesh_subnet_node_id_get(idx, &node_id); - send_node_id_status(model, ctx, status, idx, node_id); + return send_node_id_status(model, ctx, status, idx, node_id); } -static void node_identity_set(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int node_identity_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint8_t node_id, status; uint16_t idx; @@ -1743,30 +1780,28 @@ static void node_identity_set(struct bt_mesh_model *model, idx = net_buf_simple_pull_le16(buf); if (idx > 0xfff) { BT_WARN("Invalid NetKeyIndex 0x%04x", idx); - return; + return -EINVAL; } node_id = net_buf_simple_pull_u8(buf); if (node_id != 0x00 && node_id != 0x01) { BT_WARN("Invalid Node ID value 0x%02x", node_id); - return; + return -EINVAL; } status = bt_mesh_subnet_node_id_set(idx, node_id); if (status == STATUS_INVALID_NETKEY) { - send_node_id_status(model, ctx, status, idx, - BT_MESH_NODE_IDENTITY_STOPPED); - return; + return send_node_id_status(model, ctx, status, idx, + BT_MESH_NODE_IDENTITY_STOPPED); } if (status == STATUS_FEAT_NOT_SUPP) { /* Should return success, even if feature isn't supported: */ - send_node_id_status(model, ctx, STATUS_SUCCESS, idx, - BT_MESH_NODE_IDENTITY_NOT_SUPPORTED); - return; + return send_node_id_status(model, ctx, STATUS_SUCCESS, idx, + BT_MESH_NODE_IDENTITY_NOT_SUPPORTED); } - send_node_id_status(model, ctx, status, idx, node_id); + return send_node_id_status(model, ctx, status, idx, node_id); } static void create_mod_app_status(struct net_buf_simple *msg, @@ -1787,9 +1822,9 @@ static void create_mod_app_status(struct net_buf_simple *msg, } } -static void mod_app_bind(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_app_bind(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_STATUS, 9); uint16_t elem_addr, key_app_idx; @@ -1801,7 +1836,7 @@ static void mod_app_bind(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } key_app_idx = net_buf_simple_pull_le16(buf); @@ -1842,11 +1877,13 @@ send_status: if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Model App Bind Status response"); } + + return 0; } -static void mod_app_unbind(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_app_unbind(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_STATUS, 9); uint16_t elem_addr, key_app_idx; @@ -1858,7 +1895,7 @@ static void mod_app_unbind(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } key_app_idx = net_buf_simple_pull_le16(buf); @@ -1892,13 +1929,15 @@ send_status: if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Model App Unbind Status response"); } + + return 0; } #define KEY_LIST_LEN (CONFIG_BT_MESH_MODEL_KEY_COUNT * 2) -static void mod_app_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int mod_app_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { NET_BUF_SIMPLE_DEFINE(msg, MAX(BT_MESH_MODEL_BUF_LEN(OP_VND_MOD_APP_LIST, @@ -1914,7 +1953,7 @@ static void mod_app_get(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { BT_WARN("Prohibited element address"); - return; + return -EINVAL; } mod_id = buf->data; @@ -1966,6 +2005,8 @@ send_list: if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Model Application List message"); } + + return 0; } static void reset_send_start(uint16_t duration, int err, void *cb_data) @@ -1981,9 +2022,8 @@ static void reset_send_end(int err, void *cb_data) bt_mesh_reset(); } -static void node_reset(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int node_reset(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { static const struct bt_mesh_send_cb reset_cb = { .start = reset_send_start, @@ -2001,10 +2041,12 @@ static void node_reset(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, &reset_cb, NULL)) { BT_ERR("Unable to send Node Reset Status"); } + + return 0; } -static void send_friend_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx) +static int send_friend_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_FRIEND_STATUS, 1); @@ -2014,22 +2056,24 @@ static void send_friend_status(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Friend Status"); } + + return 0; } -static void friend_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int friend_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s", ctx->net_idx, ctx->app_idx, ctx->addr, buf->len, bt_hex(buf->data, buf->len)); - send_friend_status(model, ctx); + return send_friend_status(model, ctx); } -static void friend_set(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int friend_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s", ctx->net_idx, ctx->app_idx, ctx->addr, buf->len, @@ -2037,17 +2081,17 @@ static void friend_set(struct bt_mesh_model *model, if (buf->data[0] != 0x00 && buf->data[0] != 0x01) { BT_WARN("Invalid Friend value 0x%02x", buf->data[0]); - return; + return -EINVAL; } (void)bt_mesh_friend_set(buf->data[0]); - send_friend_status(model, ctx); + return send_friend_status(model, ctx); } -static void lpn_timeout_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int lpn_timeout_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_LPN_TIMEOUT_STATUS, 5); struct bt_mesh_friend *frnd; @@ -2061,7 +2105,7 @@ static void lpn_timeout_get(struct bt_mesh_model *model, if (!BT_MESH_ADDR_IS_UNICAST(lpn_addr)) { BT_WARN("Invalid LPNAddress; ignoring msg"); - return; + return -EINVAL; } bt_mesh_model_msg_init(&msg, OP_LPN_TIMEOUT_STATUS); @@ -2087,11 +2131,13 @@ send_rsp: if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send LPN PollTimeout Status"); } + + return 0; } -static void send_krp_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - uint16_t idx, uint8_t phase, uint8_t status) +static int send_krp_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, uint16_t idx, + uint8_t phase, uint8_t status) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_KRP_STATUS, 4); @@ -2104,9 +2150,11 @@ static void send_krp_status(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Key Refresh State Status"); } + + return 0; } -static void krp_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, +static int krp_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { uint8_t kr_phase, status; @@ -2115,18 +2163,18 @@ static void krp_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, idx = net_buf_simple_pull_le16(buf); if (idx > 0xfff) { BT_ERR("Invalid NetKeyIndex 0x%04x", idx); - return; + return -EINVAL; } BT_DBG("idx 0x%04x", idx); status = bt_mesh_subnet_kr_phase_get(idx, &kr_phase); - send_krp_status(model, ctx, idx, kr_phase, status); + return send_krp_status(model, ctx, idx, kr_phase, status); } -static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint8_t phase, status; uint16_t idx; @@ -2136,16 +2184,16 @@ static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, if (idx > 0xfff) { BT_ERR("Invalid NetKeyIndex 0x%04x", idx); - return; + return -EINVAL; } status = bt_mesh_subnet_kr_phase_set(idx, &phase); if (status == STATUS_CANNOT_UPDATE) { BT_ERR("Invalid kr phase transition 0x%02x", phase); - return; + return -EINVAL; } - send_krp_status(model, ctx, idx, phase, status); + return send_krp_status(model, ctx, idx, phase, status); } static uint8_t hb_pub_count_log(uint16_t val) @@ -2170,9 +2218,9 @@ struct hb_pub_param { uint16_t net_idx; } __packed; -static void hb_pub_send_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, uint8_t status, - const struct bt_mesh_hb_pub *pub) +static int hb_pub_send_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, uint8_t status, + const struct bt_mesh_hb_pub *pub) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_PUB_STATUS, 10); @@ -2192,9 +2240,11 @@ static void hb_pub_send_status(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Heartbeat Publication Status"); } + + return 0; } -static void heartbeat_pub_get(struct bt_mesh_model *model, +static int heartbeat_pub_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { @@ -2204,12 +2254,12 @@ static void heartbeat_pub_get(struct bt_mesh_model *model, bt_mesh_hb_pub_get(&pub); - hb_pub_send_status(model, ctx, STATUS_SUCCESS, &pub); + return hb_pub_send_status(model, ctx, STATUS_SUCCESS, &pub); } -static void heartbeat_pub_set(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int heartbeat_pub_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct hb_pub_param *param = (void *)buf->data; struct bt_mesh_hb_pub pub; @@ -2242,23 +2292,23 @@ static void heartbeat_pub_set(struct bt_mesh_model *model, if (param->ttl > BT_MESH_TTL_MAX && param->ttl != BT_MESH_TTL_DEFAULT) { BT_ERR("Invalid TTL value 0x%02x", param->ttl); - return; + return -EINVAL; } if (pub.net_idx > 0xfff) { BT_ERR("Invalid NetKeyIndex 0x%04x", pub.net_idx); - return; + return -EINVAL; } status = bt_mesh_hb_pub_set(&pub); rsp: - hb_pub_send_status(model, ctx, status, &pub); + return hb_pub_send_status(model, ctx, status, &pub); } -static void hb_sub_send_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - const struct bt_mesh_hb_sub *sub) +static int hb_sub_send_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const struct bt_mesh_hb_sub *sub) { BT_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_SUB_STATUS, 9); @@ -2277,9 +2327,11 @@ static void hb_sub_send_status(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Heartbeat Subscription Status"); } + + return 0; } -static void heartbeat_sub_get(struct bt_mesh_model *model, +static int heartbeat_sub_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { @@ -2289,17 +2341,18 @@ static void heartbeat_sub_get(struct bt_mesh_model *model, bt_mesh_hb_sub_get(&sub); - hb_sub_send_status(model, ctx, &sub); + return hb_sub_send_status(model, ctx, &sub); } -static void heartbeat_sub_set(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int heartbeat_sub_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint8_t period_log, status; struct bt_mesh_hb_sub sub; uint16_t sub_src, sub_dst; uint32_t period; + int err; BT_DBG("src 0x%04x", ctx->addr); @@ -2312,7 +2365,7 @@ static void heartbeat_sub_set(struct bt_mesh_model *model, if (period_log > 0x11) { BT_WARN("Prohibited subscription period 0x%02x", period_log); - return; + return -EINVAL; } period = bt_mesh_hb_pwr2(period_log); @@ -2322,7 +2375,7 @@ static void heartbeat_sub_set(struct bt_mesh_model *model, /* All errors are caused by invalid packets, which should be * ignored. */ - return; + return -EINVAL; } bt_mesh_hb_sub_get(&sub); @@ -2334,7 +2387,10 @@ static void heartbeat_sub_set(struct bt_mesh_model *model, sub.min_hops = BT_MESH_TTL_MAX; } - hb_sub_send_status(model, ctx, &sub); + err = hb_sub_send_status(model, ctx, &sub); + if (err) { + return err; + } /* MESH/NODE/CFG/HBS/BV-02-C expects us to return previous * count value and then reset it to 0. @@ -2343,6 +2399,8 @@ static void heartbeat_sub_set(struct bt_mesh_model *model, sub.dst != BT_MESH_ADDR_UNASSIGNED && !period) { bt_mesh_hb_sub_reset_count(); } + + return 0; } const struct bt_mesh_model_op bt_mesh_cfg_srv_op[] = { diff --git a/subsys/bluetooth/mesh/health_cli.c b/subsys/bluetooth/mesh/health_cli.c index cf148271fc0..b0419f1cb18 100644 --- a/subsys/bluetooth/mesh/health_cli.c +++ b/subsys/bluetooth/mesh/health_cli.c @@ -35,9 +35,9 @@ struct health_fault_param { size_t *fault_count; }; -static void health_fault_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int health_fault_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct health_fault_param *param; uint8_t test_id; @@ -49,19 +49,19 @@ static void health_fault_status(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&health_cli->ack_ctx, OP_HEALTH_FAULT_STATUS, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } test_id = net_buf_simple_pull_u8(buf); if (param->expect_test_id && test_id != *param->expect_test_id) { BT_WARN("Health fault with unexpected Test ID"); - return; + return -ENOENT; } cid = net_buf_simple_pull_le16(buf); if (cid != param->cid) { BT_WARN("Health fault with unexpected Company ID"); - return; + return -ENOENT; } if (param->test_id) { @@ -77,11 +77,13 @@ static void health_fault_status(struct bt_mesh_model *model, memcpy(param->faults, buf->data, *param->fault_count); bt_mesh_msg_ack_ctx_rx(&health_cli->ack_ctx); + + return 0; } -static void health_current_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int health_current_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct bt_mesh_health_cli *cli = model->user_data; uint8_t test_id; @@ -99,19 +101,21 @@ static void health_current_status(struct bt_mesh_model *model, if (!cli->current_status) { BT_WARN("No Current Status callback available"); - return; + return 0; } cli->current_status(cli, ctx->addr, test_id, cid, buf->data, buf->len); + + return 0; } struct health_period_param { uint8_t *divisor; }; -static void health_period_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int health_period_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct health_period_param *param; @@ -121,21 +125,23 @@ static void health_period_status(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&health_cli->ack_ctx, OP_HEALTH_PERIOD_STATUS, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } *param->divisor = net_buf_simple_pull_u8(buf); bt_mesh_msg_ack_ctx_rx(&health_cli->ack_ctx); + + return 0; } struct health_attention_param { uint8_t *attention; }; -static void health_attention_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int health_attention_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct health_attention_param *param; @@ -145,7 +151,7 @@ static void health_attention_status(struct bt_mesh_model *model, if (!bt_mesh_msg_ack_ctx_match(&health_cli->ack_ctx, OP_ATTENTION_STATUS, ctx->addr, (void **)¶m)) { - return; + return -ENOENT; } if (param->attention) { @@ -153,6 +159,8 @@ static void health_attention_status(struct bt_mesh_model *model, } bt_mesh_msg_ack_ctx_rx(&health_cli->ack_ctx); + + return 0; } const struct bt_mesh_model_op bt_mesh_health_cli_op[] = { diff --git a/subsys/bluetooth/mesh/health_srv.c b/subsys/bluetooth/mesh/health_srv.c index 1a52007e51d..e765ffb6356 100644 --- a/subsys/bluetooth/mesh/health_srv.c +++ b/subsys/bluetooth/mesh/health_srv.c @@ -72,7 +72,6 @@ static size_t health_get_current(struct bt_mesh_model *mod, uint8_t *test_id, *company_ptr; uint16_t company_id; uint8_t fault_count; - int err; bt_mesh_model_msg_init(msg, OP_HEALTH_CURRENT_STATUS); @@ -82,6 +81,8 @@ static size_t health_get_current(struct bt_mesh_model *mod, if (srv->cb && srv->cb->fault_get_cur) { fault_count = net_buf_simple_tailroom(msg); + int err; + err = srv->cb->fault_get_cur(mod, test_id, &company_id, net_buf_simple_tail(msg), &fault_count); @@ -104,9 +105,9 @@ static size_t health_get_current(struct bt_mesh_model *mod, return fault_count; } -static void health_fault_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int health_fault_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { NET_BUF_SIMPLE_DEFINE(sdu, BT_MESH_TX_SDU_MAX); uint16_t company_id; @@ -120,11 +121,13 @@ static void health_fault_get(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &sdu, NULL, NULL)) { BT_ERR("Unable to send Health Current Status response"); } + + return 0; } -static void health_fault_clear_unrel(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int health_fault_clear_unrel(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { struct bt_mesh_health_srv *srv = model->user_data; uint16_t company_id; @@ -134,13 +137,15 @@ static void health_fault_clear_unrel(struct bt_mesh_model *model, BT_DBG("company_id 0x%04x", company_id); if (srv->cb && srv->cb->fault_clear) { - srv->cb->fault_clear(model, company_id); + return srv->cb->fault_clear(model, company_id); } + + return 0; } -static void health_fault_clear(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int health_fault_clear(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { NET_BUF_SIMPLE_DEFINE(sdu, BT_MESH_TX_SDU_MAX); struct bt_mesh_health_srv *srv = model->user_data; @@ -151,7 +156,12 @@ static void health_fault_clear(struct bt_mesh_model *model, BT_DBG("company_id 0x%04x", company_id); if (srv->cb && srv->cb->fault_clear) { - srv->cb->fault_clear(model, company_id); + int err; + + err = srv->cb->fault_clear(model, company_id); + if (err) { + return err; + } } health_get_registered(model, company_id, &sdu); @@ -159,9 +169,11 @@ static void health_fault_clear(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &sdu, NULL, NULL)) { BT_ERR("Unable to send Health Current Status response"); } + + return 0; } -static void health_fault_test_unrel(struct bt_mesh_model *model, +static int health_fault_test_unrel(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { @@ -175,13 +187,15 @@ static void health_fault_test_unrel(struct bt_mesh_model *model, BT_DBG("test 0x%02x company 0x%04x", test_id, company_id); if (srv->cb && srv->cb->fault_test) { - srv->cb->fault_test(model, test_id, company_id); + return srv->cb->fault_test(model, test_id, company_id); } + + return 0; } -static void health_fault_test(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int health_fault_test(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { NET_BUF_SIMPLE_DEFINE(sdu, BT_MESH_TX_SDU_MAX); struct bt_mesh_health_srv *srv = model->user_data; @@ -201,7 +215,7 @@ static void health_fault_test(struct bt_mesh_model *model, err = srv->cb->fault_test(model, test_id, company_id); if (err) { BT_WARN("Running fault test failed with err %d", err); - return; + return err; } } @@ -210,10 +224,12 @@ static void health_fault_test(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &sdu, NULL, NULL)) { BT_ERR("Unable to send Health Current Status response"); } + + return 0; } -static void send_attention_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx) +static int send_attention_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx) { /* Needed size: opcode (2 bytes) + msg + MIC */ BT_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_STATUS, 1); @@ -231,20 +247,22 @@ static void send_attention_status(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Attention Status"); } + + return 0; } -static void attention_get(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int attention_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_DBG(""); - send_attention_status(model, ctx); + return send_attention_status(model, ctx); } -static void attention_set_unrel(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int attention_set_unrel(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { uint8_t time; @@ -253,21 +271,23 @@ static void attention_set_unrel(struct bt_mesh_model *model, BT_DBG("%u second%s", time, (time == 1U) ? "" : "s"); bt_mesh_attention(model, time); + + return 0; } -static void attention_set(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int attention_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_DBG(""); attention_set_unrel(model, ctx, buf); - send_attention_status(model, ctx); + return send_attention_status(model, ctx); } -static void send_health_period_status(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx) +static int send_health_period_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx) { /* Needed size: opcode (2 bytes) + msg + MIC */ BT_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_STATUS, 1); @@ -279,18 +299,20 @@ static void send_health_period_status(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("Unable to send Health Period Status"); } + + return 0; } -static void health_period_get(struct bt_mesh_model *model, +static int health_period_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { BT_DBG(""); - send_health_period_status(model, ctx); + return send_health_period_status(model, ctx); } -static void health_period_set_unrel(struct bt_mesh_model *model, +static int health_period_set_unrel(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { @@ -299,23 +321,25 @@ static void health_period_set_unrel(struct bt_mesh_model *model, period = net_buf_simple_pull_u8(buf); if (period > 15) { BT_WARN("Prohibited period value %u", period); - return; + return -EINVAL; } BT_DBG("period %u", period); model->pub->period_div = period; + + return 0; } -static void health_period_set(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int health_period_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { BT_DBG(""); health_period_set_unrel(model, ctx, buf); - send_health_period_status(model, ctx); + return send_health_period_status(model, ctx); } const struct bt_mesh_model_op bt_mesh_health_srv_op[] = {