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,10 +175,12 @@ struct bt_mesh_model_op {
|
||||||
* @param ctx Message context for the message.
|
* @param ctx Message context for the message.
|
||||||
* @param buf Message buffer containing the message payload, not
|
* @param buf Message buffer containing the message payload, not
|
||||||
* including the opcode.
|
* 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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf);
|
struct net_buf_simple *buf);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BT_MESH_MODEL_OP_1(b0) (b0)
|
#define BT_MESH_MODEL_OP_1(b0) (b0)
|
||||||
|
|
|
@ -670,7 +670,7 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
|
||||||
* receive the message.
|
* receive the message.
|
||||||
*/
|
*/
|
||||||
net_buf_simple_save(buf, &state);
|
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);
|
net_buf_simple_restore(buf, &state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,9 @@ static int32_t msg_timeout;
|
||||||
|
|
||||||
static struct bt_mesh_cfg_cli *cli;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct comp_data *param;
|
struct comp_data *param;
|
||||||
size_t to_copy;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_DEV_COMP_DATA_STATUS, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->page) {
|
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);
|
net_buf_simple_add_mem(param->comp, buf->data, to_copy);
|
||||||
|
|
||||||
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf,
|
struct net_buf_simple *buf,
|
||||||
uint32_t expect_status)
|
uint32_t expect_status)
|
||||||
{
|
{
|
||||||
uint8_t *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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, expect_status, ctx->addr,
|
||||||
(void **)&status)) {
|
(void **)&status)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
*status = net_buf_simple_pull_u8(buf);
|
*status = net_buf_simple_pull_u8(buf);
|
||||||
|
|
||||||
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
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 {
|
struct relay_param {
|
||||||
|
@ -118,9 +122,9 @@ struct relay_param {
|
||||||
uint8_t *transmit;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct relay_param *param;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_RELAY_STATUS, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
*param->status = net_buf_simple_pull_u8(buf);
|
*param->status = net_buf_simple_pull_u8(buf);
|
||||||
*param->transmit = net_buf_simple_pull_u8(buf);
|
*param->transmit = net_buf_simple_pull_u8(buf);
|
||||||
|
|
||||||
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
uint8_t *status;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_NET_TRANSMIT_STATUS, ctx->addr,
|
||||||
(void **)&status)) {
|
(void **)&status)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
*status = net_buf_simple_pull_u8(buf);
|
*status = net_buf_simple_pull_u8(buf);
|
||||||
|
|
||||||
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct net_key_param {
|
struct net_key_param {
|
||||||
|
@ -164,9 +172,9 @@ struct net_key_param {
|
||||||
uint16_t net_idx;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct net_key_param *param;
|
struct net_key_param *param;
|
||||||
uint16_t net_idx;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_NET_KEY_STATUS, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = net_buf_simple_pull_u8(buf);
|
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) {
|
if (param->net_idx != net_idx) {
|
||||||
BT_WARN("Net Key Status key index does not match");
|
BT_WARN("Net Key Status key index does not match");
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->status) {
|
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);
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct net_key_list_param {
|
struct net_key_list_param {
|
||||||
|
@ -201,9 +211,9 @@ struct net_key_list_param {
|
||||||
size_t *key_cnt;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct net_key_list_param *param;
|
struct net_key_list_param *param;
|
||||||
int i;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_NET_KEY_LIST, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < *param->key_cnt && buf->len >= 3; i += 2) {
|
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;
|
*param->key_cnt = i;
|
||||||
|
|
||||||
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void node_reset_status(struct bt_mesh_model *model,
|
static int node_reset_status(struct bt_mesh_model *model,
|
||||||
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
|
struct bt_mesh_msg_ctx *ctx,
|
||||||
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
bool *param = NULL;
|
bool *param = NULL;
|
||||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x",
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_NODE_RESET_STATUS, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param) {
|
if (param) {
|
||||||
*param = true;
|
*param = true;
|
||||||
}
|
}
|
||||||
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct app_key_param {
|
struct app_key_param {
|
||||||
|
@ -254,9 +269,9 @@ struct app_key_param {
|
||||||
uint16_t app_idx;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct app_key_param *param;
|
struct app_key_param *param;
|
||||||
uint16_t net_idx, app_idx;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_APP_KEY_STATUS, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = net_buf_simple_pull_u8(buf);
|
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) {
|
if (param->net_idx != net_idx || param->app_idx != app_idx) {
|
||||||
BT_WARN("App Key Status key indices did not match");
|
BT_WARN("App Key Status key indices did not match");
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->status) {
|
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);
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct app_key_list_param {
|
struct app_key_list_param {
|
||||||
|
@ -293,9 +310,9 @@ struct app_key_list_param {
|
||||||
size_t *key_cnt;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct app_key_list_param *param;
|
struct app_key_list_param *param;
|
||||||
uint16_t net_idx;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_APP_KEY_LIST, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = net_buf_simple_pull_u8(buf);
|
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) {
|
if (param->net_idx != net_idx) {
|
||||||
BT_WARN("App Key List Net Key index did not match");
|
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) {
|
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);
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mod_app_param {
|
struct mod_app_param {
|
||||||
|
@ -343,9 +362,9 @@ struct mod_app_param {
|
||||||
uint16_t cid;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
uint16_t elem_addr, mod_app_idx, mod_id, cid;
|
uint16_t elem_addr, mod_app_idx, mod_id, cid;
|
||||||
struct mod_app_param *param;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_MOD_APP_STATUS, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = net_buf_simple_pull_u8(buf);
|
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->mod_app_idx != mod_app_idx || param->mod_id != mod_id ||
|
||||||
param->cid != cid) {
|
param->cid != cid) {
|
||||||
BT_WARN("Model App Status parameters did not match");
|
BT_WARN("Model App Status parameters did not match");
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->status) {
|
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);
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mod_member_list_param {
|
struct mod_member_list_param {
|
||||||
|
@ -395,9 +416,9 @@ struct mod_member_list_param {
|
||||||
size_t *member_cnt;
|
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 net_buf_simple *buf, bool vnd,
|
||||||
struct mod_member_list_param *param)
|
struct mod_member_list_param *param)
|
||||||
{
|
{
|
||||||
uint16_t elem_addr, mod_id, cid;
|
uint16_t elem_addr, mod_id, cid;
|
||||||
uint8_t status;
|
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 ||
|
if (param->elem_addr != elem_addr || param->mod_id != mod_id ||
|
||||||
(vnd && param->cid != cid)) {
|
(vnd && param->cid != cid)) {
|
||||||
BT_WARN("Model Member List parameters did not match");
|
BT_WARN("Model Member List parameters did not match");
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf->len % 2) {
|
if (buf->len % 2) {
|
||||||
BT_WARN("Model Member List invalid length");
|
BT_WARN("Model Member List invalid length");
|
||||||
return;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < *param->member_cnt && buf->len; i++) {
|
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);
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct mod_member_list_param *param;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_SIG_MOD_APP_LIST, ctx->addr,
|
||||||
(void **)¶m)) {
|
(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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct mod_member_list_param *param;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_VND_MOD_APP_LIST, ctx->addr,
|
||||||
(void **)¶m)) {
|
(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 {
|
struct mod_pub_param {
|
||||||
|
@ -478,7 +501,7 @@ struct mod_pub_param {
|
||||||
struct bt_mesh_cfg_mod_pub *pub;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_MOD_PUB_STATUS, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->cid != CID_NVAL) {
|
if (param->cid != CID_NVAL) {
|
||||||
if (buf->len < 14) {
|
if (buf->len < 14) {
|
||||||
BT_WARN("Unexpected Mod Pub Status with SIG Model");
|
BT_WARN("Unexpected Mod Pub Status with SIG Model");
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
cid = sys_get_le16(&buf->data[10]);
|
cid = sys_get_le16(&buf->data[10]);
|
||||||
|
@ -506,7 +529,7 @@ static void mod_pub_status(struct bt_mesh_model *model,
|
||||||
} else {
|
} else {
|
||||||
if (buf->len > 12) {
|
if (buf->len > 12) {
|
||||||
BT_WARN("Unexpected Mod Pub Status with Vendor Model");
|
BT_WARN("Unexpected Mod Pub Status with Vendor Model");
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
cid = CID_NVAL;
|
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) {
|
if (mod_id != param->mod_id || cid != param->cid) {
|
||||||
BT_WARN("Mod Pub Model ID or Company ID mismatch");
|
BT_WARN("Mod Pub Model ID or Company ID mismatch");
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = net_buf_simple_pull_u8(buf);
|
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) {
|
if (elem_addr != param->elem_addr) {
|
||||||
BT_WARN("Model Pub Status for unexpected element (0x%04x)",
|
BT_WARN("Model Pub Status for unexpected element (0x%04x)",
|
||||||
elem_addr);
|
elem_addr);
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->status) {
|
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);
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mod_sub_param {
|
struct mod_sub_param {
|
||||||
|
@ -553,9 +578,9 @@ struct mod_sub_param {
|
||||||
uint16_t cid;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
uint16_t elem_addr, sub_addr, mod_id, cid;
|
uint16_t elem_addr, sub_addr, mod_id, cid;
|
||||||
struct mod_sub_param *param;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_MOD_SUB_STATUS, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = net_buf_simple_pull_u8(buf);
|
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->expect_sub && *param->expect_sub != sub_addr) ||
|
||||||
param->cid != cid) {
|
param->cid != cid) {
|
||||||
BT_WARN("Model Subscription Status parameters did not match");
|
BT_WARN("Model Subscription Status parameters did not match");
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->sub_addr) {
|
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);
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct mod_member_list_param *param;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_MOD_SUB_LIST, ctx->addr,
|
||||||
(void **)¶m)) {
|
(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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct mod_member_list_param *param;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_MOD_SUB_LIST_VND, ctx->addr,
|
||||||
(void **)¶m)) {
|
(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 {
|
struct hb_sub_param {
|
||||||
|
@ -641,9 +668,9 @@ struct hb_sub_param {
|
||||||
struct bt_mesh_cfg_hb_sub *sub;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct hb_sub_param *param;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_HEARTBEAT_SUB_STATUS, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
*param->status = net_buf_simple_pull_u8(buf);
|
*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);
|
param->sub->max = net_buf_simple_pull_u8(buf);
|
||||||
|
|
||||||
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hb_pub_param {
|
struct hb_pub_param {
|
||||||
|
@ -673,9 +702,9 @@ struct hb_pub_param {
|
||||||
struct bt_mesh_cfg_hb_pub *pub;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct hb_pub_param *param;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_HEARTBEAT_PUB_STATUS, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
*param->status = net_buf_simple_pull_u8(buf);
|
*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);
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = {
|
const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -35,9 +35,9 @@ struct health_fault_param {
|
||||||
size_t *fault_count;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct health_fault_param *param;
|
struct health_fault_param *param;
|
||||||
uint8_t test_id;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&health_cli->ack_ctx, OP_HEALTH_FAULT_STATUS, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
test_id = net_buf_simple_pull_u8(buf);
|
test_id = net_buf_simple_pull_u8(buf);
|
||||||
if (param->expect_test_id && test_id != *param->expect_test_id) {
|
if (param->expect_test_id && test_id != *param->expect_test_id) {
|
||||||
BT_WARN("Health fault with unexpected Test ID");
|
BT_WARN("Health fault with unexpected Test ID");
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
cid = net_buf_simple_pull_le16(buf);
|
cid = net_buf_simple_pull_le16(buf);
|
||||||
if (cid != param->cid) {
|
if (cid != param->cid) {
|
||||||
BT_WARN("Health fault with unexpected Company ID");
|
BT_WARN("Health fault with unexpected Company ID");
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->test_id) {
|
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);
|
memcpy(param->faults, buf->data, *param->fault_count);
|
||||||
|
|
||||||
bt_mesh_msg_ack_ctx_rx(&health_cli->ack_ctx);
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct bt_mesh_health_cli *cli = model->user_data;
|
struct bt_mesh_health_cli *cli = model->user_data;
|
||||||
uint8_t test_id;
|
uint8_t test_id;
|
||||||
|
@ -99,19 +101,21 @@ static void health_current_status(struct bt_mesh_model *model,
|
||||||
|
|
||||||
if (!cli->current_status) {
|
if (!cli->current_status) {
|
||||||
BT_WARN("No Current Status callback available");
|
BT_WARN("No Current Status callback available");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cli->current_status(cli, ctx->addr, test_id, cid, buf->data, buf->len);
|
cli->current_status(cli, ctx->addr, test_id, cid, buf->data, buf->len);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct health_period_param {
|
struct health_period_param {
|
||||||
uint8_t *divisor;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct health_period_param *param;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&health_cli->ack_ctx, OP_HEALTH_PERIOD_STATUS, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
*param->divisor = net_buf_simple_pull_u8(buf);
|
*param->divisor = net_buf_simple_pull_u8(buf);
|
||||||
|
|
||||||
bt_mesh_msg_ack_ctx_rx(&health_cli->ack_ctx);
|
bt_mesh_msg_ack_ctx_rx(&health_cli->ack_ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct health_attention_param {
|
struct health_attention_param {
|
||||||
uint8_t *attention;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct health_attention_param *param;
|
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,
|
if (!bt_mesh_msg_ack_ctx_match(&health_cli->ack_ctx, OP_ATTENTION_STATUS, ctx->addr,
|
||||||
(void **)¶m)) {
|
(void **)¶m)) {
|
||||||
return;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->attention) {
|
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);
|
bt_mesh_msg_ack_ctx_rx(&health_cli->ack_ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct bt_mesh_model_op bt_mesh_health_cli_op[] = {
|
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;
|
uint8_t *test_id, *company_ptr;
|
||||||
uint16_t company_id;
|
uint16_t company_id;
|
||||||
uint8_t fault_count;
|
uint8_t fault_count;
|
||||||
int err;
|
|
||||||
|
|
||||||
bt_mesh_model_msg_init(msg, OP_HEALTH_CURRENT_STATUS);
|
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) {
|
if (srv->cb && srv->cb->fault_get_cur) {
|
||||||
fault_count = net_buf_simple_tailroom(msg);
|
fault_count = net_buf_simple_tailroom(msg);
|
||||||
|
int err;
|
||||||
|
|
||||||
err = srv->cb->fault_get_cur(mod, test_id, &company_id,
|
err = srv->cb->fault_get_cur(mod, test_id, &company_id,
|
||||||
net_buf_simple_tail(msg),
|
net_buf_simple_tail(msg),
|
||||||
&fault_count);
|
&fault_count);
|
||||||
|
@ -104,9 +105,9 @@ static size_t health_get_current(struct bt_mesh_model *mod,
|
||||||
return fault_count;
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
NET_BUF_SIMPLE_DEFINE(sdu, BT_MESH_TX_SDU_MAX);
|
NET_BUF_SIMPLE_DEFINE(sdu, BT_MESH_TX_SDU_MAX);
|
||||||
uint16_t company_id;
|
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)) {
|
if (bt_mesh_model_send(model, ctx, &sdu, NULL, NULL)) {
|
||||||
BT_ERR("Unable to send Health Current Status response");
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct bt_mesh_health_srv *srv = model->user_data;
|
struct bt_mesh_health_srv *srv = model->user_data;
|
||||||
uint16_t company_id;
|
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);
|
BT_DBG("company_id 0x%04x", company_id);
|
||||||
|
|
||||||
if (srv->cb && srv->cb->fault_clear) {
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
NET_BUF_SIMPLE_DEFINE(sdu, BT_MESH_TX_SDU_MAX);
|
NET_BUF_SIMPLE_DEFINE(sdu, BT_MESH_TX_SDU_MAX);
|
||||||
struct bt_mesh_health_srv *srv = model->user_data;
|
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);
|
BT_DBG("company_id 0x%04x", company_id);
|
||||||
|
|
||||||
if (srv->cb && srv->cb->fault_clear) {
|
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);
|
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)) {
|
if (bt_mesh_model_send(model, ctx, &sdu, NULL, NULL)) {
|
||||||
BT_ERR("Unable to send Health Current Status response");
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
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);
|
BT_DBG("test 0x%02x company 0x%04x", test_id, company_id);
|
||||||
|
|
||||||
if (srv->cb && srv->cb->fault_test) {
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
NET_BUF_SIMPLE_DEFINE(sdu, BT_MESH_TX_SDU_MAX);
|
NET_BUF_SIMPLE_DEFINE(sdu, BT_MESH_TX_SDU_MAX);
|
||||||
struct bt_mesh_health_srv *srv = model->user_data;
|
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);
|
err = srv->cb->fault_test(model, test_id, company_id);
|
||||||
if (err) {
|
if (err) {
|
||||||
BT_WARN("Running fault test failed with err %d", 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)) {
|
if (bt_mesh_model_send(model, ctx, &sdu, NULL, NULL)) {
|
||||||
BT_ERR("Unable to send Health Current Status response");
|
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)
|
struct bt_mesh_msg_ctx *ctx)
|
||||||
{
|
{
|
||||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_STATUS, 1);
|
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)) {
|
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
|
||||||
BT_ERR("Unable to send Attention Status");
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
BT_DBG("");
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
uint8_t time;
|
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_DBG("%u second%s", time, (time == 1U) ? "" : "s");
|
||||||
|
|
||||||
bt_mesh_attention(model, time);
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
BT_DBG("");
|
BT_DBG("");
|
||||||
|
|
||||||
attention_set_unrel(model, ctx, buf);
|
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)
|
struct bt_mesh_msg_ctx *ctx)
|
||||||
{
|
{
|
||||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_STATUS, 1);
|
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)) {
|
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
|
||||||
BT_ERR("Unable to send Health Period Status");
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
BT_DBG("");
|
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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
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);
|
period = net_buf_simple_pull_u8(buf);
|
||||||
if (period > 15) {
|
if (period > 15) {
|
||||||
BT_WARN("Prohibited period value %u", period);
|
BT_WARN("Prohibited period value %u", period);
|
||||||
return;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
BT_DBG("period %u", period);
|
BT_DBG("period %u", period);
|
||||||
|
|
||||||
model->pub->period_div = 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 bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
BT_DBG("");
|
BT_DBG("");
|
||||||
|
|
||||||
health_period_set_unrel(model, ctx, buf);
|
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[] = {
|
const struct bt_mesh_model_op bt_mesh_health_srv_op[] = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue