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
|
@ -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[] = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue