Bluetooth: Mesh: Add return value for opcode callback
``` 3.7.3.4 Message error procedure When receiving a message that is not understood by an element, it shall ignore the message. Note: A message can be falsely identified as a valid message, passing the NetMIC and TransMIC authentication using a known network key and application key even though that message was sent using different keys. The decryption of that message using the wrong keys would result in a message that is not understood by the element. The probability of such a situation occurring is small but not insignificant. A message that is not understood includes messages that have one or more of the following conditions: • The application opcode is unknown by the receiving element. • The access message size for the application opcode is incorrect. • The application parameters contain values that are currently Prohibited. Note: An element that sends an acknowledged message that is not understood by a peer node will not receive any response message. ``` Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
This commit is contained in:
parent
cd881e0562
commit
b9422ea9f3
6 changed files with 541 additions and 418 deletions
|
@ -175,8 +175,10 @@ 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,
|
||||
int (*const func)(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf);
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ static int32_t msg_timeout;
|
|||
|
||||
static struct bt_mesh_cfg_cli *cli;
|
||||
|
||||
static void comp_data_status(struct bt_mesh_model *model,
|
||||
static int comp_data_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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,9 +62,11 @@ 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,
|
||||
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)
|
||||
|
@ -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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,7 +122,7 @@ struct relay_param {
|
|||
uint8_t *transmit;
|
||||
};
|
||||
|
||||
static void relay_status(struct bt_mesh_model *model,
|
||||
static int relay_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -130,16 +134,18 @@ 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,
|
||||
static int net_transmit_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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,7 +172,7 @@ struct net_key_param {
|
|||
uint16_t net_idx;
|
||||
};
|
||||
|
||||
static void net_key_status(struct bt_mesh_model *model,
|
||||
static int net_key_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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,7 +211,7 @@ struct net_key_list_param {
|
|||
size_t *key_cnt;
|
||||
};
|
||||
|
||||
static void net_key_list(struct bt_mesh_model *model,
|
||||
static int net_key_list(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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,7 +269,7 @@ struct app_key_param {
|
|||
uint16_t app_idx;
|
||||
};
|
||||
|
||||
static void app_key_status(struct bt_mesh_model *model,
|
||||
static int app_key_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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,7 +310,7 @@ struct app_key_list_param {
|
|||
size_t *key_cnt;
|
||||
};
|
||||
|
||||
static void app_key_list(struct bt_mesh_model *model,
|
||||
static int app_key_list(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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,7 +362,7 @@ struct mod_app_param {
|
|||
uint16_t cid;
|
||||
};
|
||||
|
||||
static void mod_app_status(struct bt_mesh_model *model,
|
||||
static int mod_app_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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,7 +416,7 @@ struct mod_member_list_param {
|
|||
size_t *member_cnt;
|
||||
};
|
||||
|
||||
static void mod_member_list_handle(struct bt_mesh_msg_ctx *ctx,
|
||||
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)
|
||||
{
|
||||
|
@ -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,9 +453,11 @@ 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,
|
||||
static int mod_app_list(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -446,13 +469,13 @@ 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,
|
||||
static int mod_app_list_vnd(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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,7 +578,7 @@ struct mod_sub_param {
|
|||
uint16_t cid;
|
||||
};
|
||||
|
||||
static void mod_sub_status(struct bt_mesh_model *model,
|
||||
static int mod_sub_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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,9 +623,11 @@ 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,
|
||||
static int mod_sub_list(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -612,13 +639,13 @@ 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,
|
||||
static int mod_sub_list_vnd(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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,7 +668,7 @@ struct hb_sub_param {
|
|||
struct bt_mesh_cfg_hb_sub *sub;
|
||||
};
|
||||
|
||||
static void hb_sub_status(struct bt_mesh_model *model,
|
||||
static int hb_sub_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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,7 +702,7 @@ struct hb_pub_param {
|
|||
struct bt_mesh_cfg_hb_pub *pub;
|
||||
};
|
||||
|
||||
static void hb_pub_status(struct bt_mesh_model *model,
|
||||
static int hb_pub_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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[] = {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -35,7 +35,7 @@ struct health_fault_param {
|
|||
size_t *fault_count;
|
||||
};
|
||||
|
||||
static void health_fault_status(struct bt_mesh_model *model,
|
||||
static int health_fault_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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,9 +77,11 @@ 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,
|
||||
static int health_current_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -99,17 +101,19 @@ 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,
|
||||
static int health_period_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -121,19 +125,21 @@ 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,
|
||||
static int health_attention_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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[] = {
|
||||
|
|
|
@ -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,7 +105,7 @@ static size_t health_get_current(struct bt_mesh_model *mod,
|
|||
return fault_count;
|
||||
}
|
||||
|
||||
static void health_fault_get(struct bt_mesh_model *model,
|
||||
static int health_fault_get(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -120,9 +121,11 @@ 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,
|
||||
static int health_fault_clear_unrel(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -134,11 +137,13 @@ 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,
|
||||
static int health_fault_clear(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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,11 +187,13 @@ 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,
|
||||
static int health_fault_test(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -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,9 +224,11 @@ 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,
|
||||
static int send_attention_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
|
@ -231,18 +247,20 @@ 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,
|
||||
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,
|
||||
static int attention_set_unrel(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -253,9 +271,11 @@ 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,
|
||||
static int attention_set(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -263,10 +283,10 @@ static void attention_set(struct bt_mesh_model *model,
|
|||
|
||||
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,
|
||||
static int send_health_period_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
|
@ -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,15 +321,17 @@ 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,
|
||||
static int health_period_set(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
|
@ -315,7 +339,7 @@ static void health_period_set(struct bt_mesh_model *model,
|
|||
|
||||
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[] = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue