diff --git a/apps/blemesh/src/main.c b/apps/blemesh/src/main.c index 65270554b..56d0476f8 100644 --- a/apps/blemesh/src/main.c +++ b/apps/blemesh/src/main.c @@ -144,11 +144,12 @@ static struct bt_mesh_model_pub gen_onoff_pub; static uint8_t gen_on_off_state; static int16_t gen_level_state; -static void gen_onoff_status(struct bt_mesh_model *model, +static int gen_onoff_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx) { struct os_mbuf *msg = NET_BUF_SIMPLE(3); uint8_t *status; + int rc; console_printf("#mesh-onoff STATUS\n"); @@ -156,23 +157,25 @@ static void gen_onoff_status(struct bt_mesh_model *model, status = net_buf_simple_add(msg, 1); *status = gen_on_off_state; - if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { + rc = bt_mesh_model_send(model, ctx, msg, NULL, NULL); + if (rc) { console_printf("#mesh-onoff STATUS: send status failed\n"); } os_mbuf_free_chain(msg); + return rc; } -static void gen_onoff_get(struct bt_mesh_model *model, +static int gen_onoff_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { console_printf("#mesh-onoff GET\n"); - gen_onoff_status(model, ctx); + return gen_onoff_status(model, ctx); } -static void gen_onoff_set(struct bt_mesh_model *model, +static int gen_onoff_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -181,10 +184,10 @@ static void gen_onoff_set(struct bt_mesh_model *model, gen_on_off_state = buf->om_data[0]; hal_gpio_write(LED_2, !gen_on_off_state); - gen_onoff_status(model, ctx); + return gen_onoff_status(model, ctx); } -static void gen_onoff_set_unack(struct bt_mesh_model *model, +static int gen_onoff_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -192,6 +195,7 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model, gen_on_off_state = buf->om_data[0]; hal_gpio_write(LED_2, !gen_on_off_state); + return 0; } static const struct bt_mesh_model_op gen_onoff_op[] = { @@ -201,48 +205,56 @@ static const struct bt_mesh_model_op gen_onoff_op[] = { BT_MESH_MODEL_OP_END, }; -static void gen_level_status(struct bt_mesh_model *model, +static int gen_level_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx) { struct os_mbuf *msg = NET_BUF_SIMPLE(4); + int rc; console_printf("#mesh-level STATUS\n"); bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_2(0x82, 0x08)); net_buf_simple_add_le16(msg, gen_level_state); - if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { + rc = bt_mesh_model_send(model, ctx, msg, NULL, NULL); + if (rc) { console_printf("#mesh-level STATUS: send status failed\n"); } os_mbuf_free_chain(msg); + return rc; } -static void gen_level_get(struct bt_mesh_model *model, +static int gen_level_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { console_printf("#mesh-level GET\n"); - gen_level_status(model, ctx); + return gen_level_status(model, ctx); } -static void gen_level_set(struct bt_mesh_model *model, +static int gen_level_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { int16_t level; + int rc; level = (int16_t) net_buf_simple_pull_le16(buf); console_printf("#mesh-level SET: level=%d\n", level); - gen_level_status(model, ctx); + rc = gen_level_status(model, ctx); + if (rc) { + return rc; + } gen_level_state = level; console_printf("#mesh-level: level=%d\n", gen_level_state); + return 0; } -static void gen_level_set_unack(struct bt_mesh_model *model, +static int gen_level_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -253,9 +265,10 @@ static void gen_level_set_unack(struct bt_mesh_model *model, gen_level_state = level; console_printf("#mesh-level: level=%d\n", gen_level_state); + return 0; } -static void gen_delta_set(struct bt_mesh_model *model, +static int gen_delta_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -268,9 +281,10 @@ static void gen_delta_set(struct bt_mesh_model *model, gen_level_state += delta_level; console_printf("#mesh-level: level=%d\n", gen_level_state); + return 0; } -static void gen_delta_set_unack(struct bt_mesh_model *model, +static int gen_delta_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -281,18 +295,21 @@ static void gen_delta_set_unack(struct bt_mesh_model *model, gen_level_state += delta_level; console_printf("#mesh-level: level=%d\n", gen_level_state); + return 0; } -static void gen_move_set(struct bt_mesh_model *model, +static int gen_move_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { + return 0; } -static void gen_move_set_unack(struct bt_mesh_model *model, +static int gen_move_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { + return 0; } static const struct bt_mesh_model_op gen_level_op[] = { @@ -317,11 +334,12 @@ static struct bt_mesh_model root_models[] = { static struct bt_mesh_model_pub vnd_model_pub; -static void vnd_model_recv(struct bt_mesh_model *model, +static int vnd_model_recv(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { struct os_mbuf *msg = NET_BUF_SIMPLE(3); + int rc; console_printf("#vendor-model-recv\n"); @@ -331,11 +349,13 @@ static void vnd_model_recv(struct bt_mesh_model *model, bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_3(0x01, CID_VENDOR)); os_mbuf_append(msg, buf->om_data, buf->om_len); + rc = bt_mesh_model_send(model, ctx, msg, NULL, NULL); if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { console_printf("#vendor-model-recv: send rsp failed\n"); } os_mbuf_free_chain(msg); + return rc; } static const struct bt_mesh_model_op vnd_model_op[] = { diff --git a/apps/blemesh_models_example_1/src/main.c b/apps/blemesh_models_example_1/src/main.c index 736d4d32b..80a69c705 100644 --- a/apps/blemesh_models_example_1/src/main.c +++ b/apps/blemesh_models_example_1/src/main.c @@ -68,19 +68,19 @@ #define BT_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x03) #define BT_MESH_MODEL_OP_GEN_ONOFF_STATUS BT_MESH_MODEL_OP_2(0x82, 0x04) -static void gen_onoff_set(struct bt_mesh_model *model, +static int gen_onoff_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf); -static void gen_onoff_set_unack(struct bt_mesh_model *model, +static int gen_onoff_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf); -static void gen_onoff_get(struct bt_mesh_model *model, +static int gen_onoff_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf); -static void gen_onoff_status(struct bt_mesh_model *model, +static int gen_onoff_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf); @@ -318,26 +318,29 @@ static uint16_t primary_net_idx; * */ -static void gen_onoff_get(struct bt_mesh_model *model, +static int gen_onoff_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { struct os_mbuf *msg = NET_BUF_SIMPLE(2 + 1 + 4); struct onoff_state *state = model->user_data; + int rc; BT_INFO("addr 0x%04x onoff 0x%02x", bt_mesh_model_elem(model)->addr, state->current); bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_GEN_ONOFF_STATUS); net_buf_simple_add_u8(msg, state->current); - if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { + rc = bt_mesh_model_send(model, ctx, msg, NULL, NULL); + if (rc) { BT_ERR("Unable to send On Off Status response"); } os_mbuf_free_chain(msg); + return rc; } -static void gen_onoff_set_unack(struct bt_mesh_model *model, +static int gen_onoff_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -372,23 +375,34 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model, BT_MESH_MODEL_OP_GEN_ONOFF_STATUS); net_buf_simple_add_u8(msg, state->current); err = bt_mesh_model_publish(model); - if (err) { + if (err != 0) { BT_ERR("bt_mesh_model_publish err %d", err); + return err; } } + return 0; } -static void gen_onoff_set(struct bt_mesh_model *model, +static int gen_onoff_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { BT_INFO(""); + int rc; - gen_onoff_set_unack(model, ctx, buf); - gen_onoff_get(model, ctx, buf); + rc = gen_onoff_set_unack(model, ctx, buf); + if (rc != 0) { + return rc; + } + + rc = gen_onoff_get(model, ctx, buf); + if (rc != 0) { + return rc; + } + return 0; } -static void gen_onoff_status(struct bt_mesh_model *model, +static int gen_onoff_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -398,6 +412,7 @@ static void gen_onoff_status(struct bt_mesh_model *model, BT_INFO("Node 0x%04x OnOff status from 0x%04x with state 0x%02x", bt_mesh_model_elem(model)->addr, ctx->addr, state); + return 0; } static int output_number(bt_mesh_output_action_t action, uint32_t number) diff --git a/apps/blemesh_models_example_2/src/device_composition.c b/apps/blemesh_models_example_2/src/device_composition.c index 5dfeaf8ed..40ede5012 100644 --- a/apps/blemesh_models_example_2/src/device_composition.c +++ b/apps/blemesh_models_example_2/src/device_composition.c @@ -147,7 +147,7 @@ static struct bt_mesh_elem elements[]; /* message handlers (Start) */ /* Generic OnOff Server message handlers */ -static void gen_onoff_get(struct bt_mesh_model *model, +static int gen_onoff_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -168,16 +168,17 @@ static void gen_onoff_get(struct bt_mesh_model *model, } os_mbuf_free_chain(msg); + return 0; } -void gen_onoff_publish(struct bt_mesh_model *model) +int gen_onoff_publish(struct bt_mesh_model *model) { int err; struct os_mbuf *msg = model->pub->msg; struct generic_onoff_state *state = model->user_data; if (model->pub->addr == BT_MESH_ADDR_UNASSIGNED) { - return; + return 0; } bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_GEN_ONOFF_STATUS); @@ -193,21 +194,23 @@ void gen_onoff_publish(struct bt_mesh_model *model) if (err) { printk("bt_mesh_model_publish err %d\n", err); } + return err; } -static void gen_onoff_set_unack(struct bt_mesh_model *model, +static int gen_onoff_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { uint8_t tid, onoff, tt, delay; int64_t now; + int err; struct generic_onoff_state *state = model->user_data; onoff = net_buf_simple_pull_u8(buf); tid = net_buf_simple_pull_u8(buf); if (onoff > STATE_ON) { - return; + return 0; } now = k_uptime_get(); @@ -215,7 +218,7 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - return; + return 0; } switch (buf->om_len) { @@ -226,13 +229,13 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -247,8 +250,7 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model, if (state->target_onoff != state->onoff) { onoff_tt_values(state, tt, delay); } else { - gen_onoff_publish(model); - return; + return gen_onoff_publish(model); } /* For Instantaneous Transition */ @@ -257,23 +259,28 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model, } state->transition->just_started = true; - gen_onoff_publish(model); + err = gen_onoff_publish(model); onoff_handler(state); + if (err) { + return err; + } + return 0; } -static void gen_onoff_set(struct bt_mesh_model *model, +static int gen_onoff_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { uint8_t tid, onoff, tt, delay; int64_t now; + int rc; struct generic_onoff_state *state = model->user_data; onoff = net_buf_simple_pull_u8(buf); tid = net_buf_simple_pull_u8(buf); if (onoff > STATE_ON) { - return; + return 0; } now = k_uptime_get(); @@ -281,8 +288,8 @@ static void gen_onoff_set(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - gen_onoff_get(model, ctx, buf); - return; + rc = gen_onoff_get(model, ctx, buf); + return rc; } switch (buf->om_len) { @@ -293,13 +300,13 @@ static void gen_onoff_set(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -315,8 +322,8 @@ static void gen_onoff_set(struct bt_mesh_model *model, onoff_tt_values(state, tt, delay); } else { gen_onoff_get(model, ctx, buf); - gen_onoff_publish(model); - return; + rc = gen_onoff_publish(model); + return rc; } /* For Instantaneous Transition */ @@ -326,12 +333,13 @@ static void gen_onoff_set(struct bt_mesh_model *model, state->transition->just_started = true; gen_onoff_get(model, ctx, buf); - gen_onoff_publish(model); + rc = gen_onoff_publish(model); onoff_handler(state); + return rc; } /* Generic OnOff Client message handlers */ -static void gen_onoff_status(struct bt_mesh_model *model, +static int gen_onoff_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -342,10 +350,11 @@ static void gen_onoff_status(struct bt_mesh_model *model, printk("Target OnOff = %02x\n", net_buf_simple_pull_u8(buf)); printk("Remaining Time = %02x\n", net_buf_simple_pull_u8(buf)); } + return 0; } /* Generic Level Server message handlers */ -static void gen_level_get(struct bt_mesh_model *model, +static int gen_level_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -366,16 +375,17 @@ static void gen_level_get(struct bt_mesh_model *model, } os_mbuf_free_chain(msg); + return 0; } -void gen_level_publish(struct bt_mesh_model *model) +int gen_level_publish(struct bt_mesh_model *model) { int err; struct os_mbuf *msg = model->pub->msg; struct generic_level_state *state = model->user_data; if (model->pub->addr == BT_MESH_ADDR_UNASSIGNED) { - return; + return 0; } bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_GEN_LEVEL_STATUS); @@ -391,9 +401,10 @@ void gen_level_publish(struct bt_mesh_model *model) if (err) { printk("bt_mesh_model_publish err %d\n", err); } + return err; } -static void gen_level_set_unack(struct bt_mesh_model *model, +static int gen_level_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -410,7 +421,7 @@ static void gen_level_set_unack(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - return; + return 0; } switch (buf->om_len) { @@ -421,13 +432,13 @@ static void gen_level_set_unack(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -443,7 +454,7 @@ static void gen_level_set_unack(struct bt_mesh_model *model, level_tt_values(state, tt, delay); } else { gen_level_publish(model); - return; + return 0; } /* For Instantaneous Transition */ @@ -463,9 +474,10 @@ static void gen_level_set_unack(struct bt_mesh_model *model, transition_type = LEVEL_TEMP_TT; level_temp_handler(state); } + return 0; } -static void gen_level_set(struct bt_mesh_model *model, +static int gen_level_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -483,7 +495,7 @@ static void gen_level_set(struct bt_mesh_model *model, state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { gen_level_get(model, ctx, buf); - return; + return 0; } switch (buf->om_len) { @@ -494,13 +506,13 @@ static void gen_level_set(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -517,7 +529,7 @@ static void gen_level_set(struct bt_mesh_model *model, } else { gen_level_get(model, ctx, buf); gen_level_publish(model); - return; + return 0; } /* For Instantaneous Transition */ @@ -538,9 +550,10 @@ static void gen_level_set(struct bt_mesh_model *model, transition_type = LEVEL_TEMP_TT; level_temp_handler(state); } + return 0; } -static void gen_delta_set_unack(struct bt_mesh_model *model, +static int gen_delta_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -559,7 +572,7 @@ static void gen_delta_set_unack(struct bt_mesh_model *model, (now - state->last_msg_timestamp <= K_SECONDS(6))) { if (state->last_delta == delta) { - return; + return 0; } tmp32 = state->last_level + delta; @@ -576,13 +589,13 @@ static void gen_delta_set_unack(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -605,8 +618,7 @@ static void gen_delta_set_unack(struct bt_mesh_model *model, if (state->target_level != state->level) { level_tt_values(state, tt, delay); } else { - gen_level_publish(model); - return; + return gen_level_publish(model); } /* For Instantaneous Transition */ @@ -627,9 +639,10 @@ static void gen_delta_set_unack(struct bt_mesh_model *model, transition_type = LEVEL_TEMP_TT_DELTA; level_temp_handler(state); } + return 0; } -static void gen_delta_set(struct bt_mesh_model *model, +static int gen_delta_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -649,7 +662,7 @@ static void gen_delta_set(struct bt_mesh_model *model, if (state->last_delta == delta) { gen_level_get(model, ctx, buf); - return; + return 0; } tmp32 = state->last_level + delta; @@ -666,13 +679,13 @@ static void gen_delta_set(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -697,7 +710,7 @@ static void gen_delta_set(struct bt_mesh_model *model, } else { gen_level_get(model, ctx, buf); gen_level_publish(model); - return; + return 0; } /* For Instantaneous Transition */ @@ -718,14 +731,16 @@ static void gen_delta_set(struct bt_mesh_model *model, transition_type = LEVEL_TEMP_TT_DELTA; level_temp_handler(state); } + return 0; } -static void gen_level_move_get(struct bt_mesh_model *model, +static int gen_level_move_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { struct os_mbuf *msg = NET_BUF_SIMPLE(2 + 5 + 4); struct generic_level_state *state = model->user_data; + int rc; bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_GEN_LEVEL_STATUS); net_buf_simple_add_le16(msg, state->level); @@ -740,21 +755,23 @@ static void gen_level_move_get(struct bt_mesh_model *model, net_buf_simple_add_u8(msg, UNKNOWN_VALUE); } - if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { + rc = bt_mesh_model_send(model, ctx, msg, NULL, NULL); + if (rc) { printk("Unable to send GEN_LEVEL_SRV Status response\n"); } os_mbuf_free_chain(msg); + return rc; } -static void gen_level_move_publish(struct bt_mesh_model *model) +static int gen_level_move_publish(struct bt_mesh_model *model) { int err; struct os_mbuf *msg = model->pub->msg; struct generic_level_state *state = model->user_data; if (model->pub->addr == BT_MESH_ADDR_UNASSIGNED) { - return; + return 0; } bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_GEN_LEVEL_STATUS); @@ -774,9 +791,10 @@ static void gen_level_move_publish(struct bt_mesh_model *model) if (err) { printk("bt_mesh_model_publish err %d\n", err); } + return err; } -static void gen_move_set_unack(struct bt_mesh_model *model, +static int gen_move_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -785,6 +803,7 @@ static void gen_move_set_unack(struct bt_mesh_model *model, int32_t tmp32; int64_t now; struct generic_level_state *state = model->user_data; + int rc; delta = (int16_t) net_buf_simple_pull_le16(buf); tid = net_buf_simple_pull_u8(buf); @@ -794,7 +813,7 @@ static void gen_move_set_unack(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - return; + return 0; } switch (buf->om_len) { @@ -805,13 +824,13 @@ static void gen_move_set_unack(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -835,16 +854,16 @@ static void gen_move_set_unack(struct bt_mesh_model *model, if (state->target_level != state->level) { level_tt_values(state, tt, delay); } else { - gen_level_move_publish(model); - return; + rc = gen_level_move_publish(model); + return rc; } if (state->transition->counter == 0) { - return; + return 0; } state->transition->just_started = true; - gen_level_move_publish(model); + rc = gen_level_move_publish(model); if (bt_mesh_model_elem(model)->addr == elements[0].addr) { /* Root element */ @@ -855,9 +874,10 @@ static void gen_move_set_unack(struct bt_mesh_model *model, transition_type = LEVEL_TEMP_TT_MOVE; level_temp_handler(state); } + return rc; } -static void gen_move_set(struct bt_mesh_model *model, +static int gen_move_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -866,6 +886,7 @@ static void gen_move_set(struct bt_mesh_model *model, int32_t tmp32; int64_t now; struct generic_level_state *state = model->user_data; + int rc; delta = (int16_t) net_buf_simple_pull_le16(buf); tid = net_buf_simple_pull_u8(buf); @@ -875,8 +896,8 @@ static void gen_move_set(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - gen_level_move_get(model, ctx, buf); - return; + rc = gen_level_move_get(model, ctx, buf); + return rc; } switch (buf->om_len) { @@ -887,13 +908,13 @@ static void gen_move_set(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -918,17 +939,17 @@ static void gen_move_set(struct bt_mesh_model *model, level_tt_values(state, tt, delay); } else { gen_level_move_get(model, ctx, buf); - gen_level_move_publish(model); - return; + rc = gen_level_move_publish(model); + return rc; } if (state->transition->counter == 0) { - return; + return 0; } state->transition->just_started = true; gen_level_move_get(model, ctx, buf); - gen_level_move_publish(model); + rc = gen_level_move_publish(model); if (bt_mesh_model_elem(model)->addr == elements[0].addr) { /* Root element */ @@ -939,10 +960,11 @@ static void gen_move_set(struct bt_mesh_model *model, transition_type = LEVEL_TEMP_TT_MOVE; level_temp_handler(state); } + return rc; } /* Generic Level Client message handlers */ -static void gen_level_status(struct bt_mesh_model *model, +static int gen_level_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -953,10 +975,11 @@ static void gen_level_status(struct bt_mesh_model *model, printk("Target Level = %04x\n", net_buf_simple_pull_le16(buf)); printk("Remaining Time = %02x\n", net_buf_simple_pull_u8(buf)); } + return 0; } /* Generic Default Transition Time Server message handlers */ -static void gen_def_trans_time_get(struct bt_mesh_model *model, +static int gen_def_trans_time_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -971,16 +994,17 @@ static void gen_def_trans_time_get(struct bt_mesh_model *model, } os_mbuf_free_chain(msg); + return 0; } -static void gen_def_trans_time_publish(struct bt_mesh_model *model) +static int gen_def_trans_time_publish(struct bt_mesh_model *model) { int err; struct os_mbuf *msg = model->pub->msg; struct gen_def_trans_time_state *state = model->user_data; if (model->pub->addr == BT_MESH_ADDR_UNASSIGNED) { - return; + return 0; } bt_mesh_model_msg_init(msg, BT_MESH_MODEL_GEN_DEF_TRANS_TIME_STATUS); @@ -990,6 +1014,7 @@ static void gen_def_trans_time_publish(struct bt_mesh_model *model) if (err) { printk("bt_mesh_model_publish err %d\n", err); } + return err; } static bool gen_def_trans_time_setunack(struct bt_mesh_model *model, @@ -1017,71 +1042,78 @@ static bool gen_def_trans_time_setunack(struct bt_mesh_model *model, return true; } -static void gen_def_trans_time_set_unack(struct bt_mesh_model *model, +static int gen_def_trans_time_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { if (gen_def_trans_time_setunack(model, ctx, buf) == true) { - gen_def_trans_time_publish(model); + return gen_def_trans_time_publish(model); } + return 0; } -static void gen_def_trans_time_set(struct bt_mesh_model *model, +static int gen_def_trans_time_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { if (gen_def_trans_time_setunack(model, ctx, buf) == true) { gen_def_trans_time_get(model, ctx, buf); - gen_def_trans_time_publish(model); + return gen_def_trans_time_publish(model); } + return 0; } /* Generic Default Transition Time Client message handlers */ -static void gen_def_trans_time_status(struct bt_mesh_model *model, +static int gen_def_trans_time_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { printk("Acknownledgement from GEN_DEF_TT_SRV\n"); printk("Transition Time = %02x\n", net_buf_simple_pull_u8(buf)); + return 0; } /* Generic Power OnOff Server message handlers */ -static void gen_onpowerup_get(struct bt_mesh_model *model, +static int gen_onpowerup_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { struct os_mbuf *msg = NET_BUF_SIMPLE(2 + 1 + 4); struct generic_onpowerup_state *state = model->user_data; + int rc; bt_mesh_model_msg_init(msg, BT_MESH_MODEL_GEN_ONPOWERUP_STATUS); net_buf_simple_add_u8(msg, state->onpowerup); - if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { + rc = bt_mesh_model_send(model, ctx, msg, NULL, NULL); + if (rc) { printk("Unable to send GEN_POWER_ONOFF_SRV Status response\n"); } os_mbuf_free_chain(msg); + return rc; } /* Generic Power OnOff Client message handlers */ -static void gen_onpowerup_status(struct bt_mesh_model *model, +static int gen_onpowerup_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { printk("Acknownledgement from GEN_POWER_ONOFF_SRV\n"); printk("OnPowerUp = %02x\n", net_buf_simple_pull_u8(buf)); + return 0; } /* Generic Power OnOff Setup Server message handlers */ -static void gen_onpowerup_publish(struct bt_mesh_model *model) +static int gen_onpowerup_publish(struct bt_mesh_model *model) { int err; struct os_mbuf *msg = model->pub->msg; struct generic_onpowerup_state *state = model->user_data; if (model->pub->addr == BT_MESH_ADDR_UNASSIGNED) { - return; + return 0; } bt_mesh_model_msg_init(msg, BT_MESH_MODEL_GEN_ONPOWERUP_STATUS); @@ -1091,6 +1123,7 @@ static void gen_onpowerup_publish(struct bt_mesh_model *model) if (err) { printk("bt_mesh_model_publish err %d\n", err); } + return err; } static bool gen_onpowerup_setunack(struct bt_mesh_model *model, @@ -1117,32 +1150,35 @@ static bool gen_onpowerup_setunack(struct bt_mesh_model *model, return true; } -static void gen_onpowerup_set_unack(struct bt_mesh_model *model, +static int gen_onpowerup_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { if (gen_onpowerup_setunack(model, ctx, buf) == true) { - gen_onpowerup_publish(model); + return gen_onpowerup_publish(model); } + return 0; } -static void gen_onpowerup_set(struct bt_mesh_model *model, +static int gen_onpowerup_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { if (gen_onpowerup_setunack(model, ctx, buf) == true) { gen_onpowerup_get(model, ctx, buf); - gen_onpowerup_publish(model); + return gen_onpowerup_publish(model); } + return 0; } /* Vendor Model message handlers*/ -static void vnd_get(struct bt_mesh_model *model, +static int vnd_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { struct os_mbuf *msg = NET_BUF_SIMPLE(3 + 6 + 4); struct vendor_state *state = model->user_data; + int err; /* This is dummy response for demo purpose */ state->response = 0xA578FEB3; @@ -1151,14 +1187,16 @@ static void vnd_get(struct bt_mesh_model *model, net_buf_simple_add_le16(msg, state->current); net_buf_simple_add_le32(msg, state->response); - if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { + err = bt_mesh_model_send(model, ctx, msg, NULL, NULL); + if (err) { printk("Unable to send VENDOR Status response\n"); } os_mbuf_free_chain(msg); + return err; } -static void vnd_set_unack(struct bt_mesh_model *model, +static int vnd_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1175,7 +1213,7 @@ static void vnd_set_unack(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - return; + return 0; } state->last_tid = tid; @@ -1193,27 +1231,37 @@ static void vnd_set_unack(struct bt_mesh_model *model, /* LED2 Off */ hal_gpio_write(led_device[1], 1); } + return 0; } -static void vnd_set(struct bt_mesh_model *model, +static int vnd_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { - vnd_set_unack(model, ctx, buf); - vnd_get(model, ctx, buf); + int rc; + rc = vnd_set_unack(model, ctx, buf); + if (rc) { + return rc; + } + rc = vnd_get(model, ctx, buf); + if (rc) { + return rc; + } + return 0; } -static void vnd_status(struct bt_mesh_model *model, +static int vnd_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { printk("Acknownledgement from Vendor\n"); printk("cmd = %04x\n", net_buf_simple_pull_le16(buf)); printk("response = %08lx\n", net_buf_simple_pull_le32(buf)); + return 0; } /* Light Lightness Server message handlers */ -static void light_lightness_get(struct bt_mesh_model *model, +static int light_lightness_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1234,16 +1282,17 @@ static void light_lightness_get(struct bt_mesh_model *model, } os_mbuf_free_chain(msg); + return 0; } -void light_lightness_publish(struct bt_mesh_model *model) +int light_lightness_publish(struct bt_mesh_model *model) { int err; struct os_mbuf *msg = model->pub->msg; struct light_lightness_state *state = model->user_data; if (model->pub->addr == BT_MESH_ADDR_UNASSIGNED) { - return; + return 0; } bt_mesh_model_msg_init(msg, BT_MESH_MODEL_LIGHT_LIGHTNESS_STATUS); @@ -1259,9 +1308,10 @@ void light_lightness_publish(struct bt_mesh_model *model) if (err) { printk("bt_mesh_model_publish err %d\n", err); } + return err; } -static void light_lightness_set_unack(struct bt_mesh_model *model, +static int light_lightness_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1278,7 +1328,7 @@ static void light_lightness_set_unack(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - return; + return 0; } switch (buf->om_len) { @@ -1289,13 +1339,13 @@ static void light_lightness_set_unack(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -1318,7 +1368,7 @@ static void light_lightness_set_unack(struct bt_mesh_model *model, light_lightness_actual_tt_values(state, tt, delay); } else { light_lightness_publish(model); - return; + return 0; } /* For Instantaneous Transition */ @@ -1329,9 +1379,10 @@ static void light_lightness_set_unack(struct bt_mesh_model *model, state->transition->just_started = true; light_lightness_publish(model); light_lightness_actual_handler(state); + return 0; } -static void light_lightness_set(struct bt_mesh_model *model, +static int light_lightness_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1339,6 +1390,7 @@ static void light_lightness_set(struct bt_mesh_model *model, uint16_t actual; int64_t now; struct light_lightness_state *state = model->user_data; + int rc; actual = net_buf_simple_pull_le16(buf); tid = net_buf_simple_pull_u8(buf); @@ -1348,8 +1400,7 @@ static void light_lightness_set(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - light_lightness_get(model, ctx, buf); - return; + return light_lightness_get(model, ctx, buf); } switch (buf->om_len) { @@ -1360,13 +1411,13 @@ static void light_lightness_set(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -1388,9 +1439,9 @@ static void light_lightness_set(struct bt_mesh_model *model, if (state->target_actual != state->actual) { light_lightness_actual_tt_values(state, tt, delay); } else { - light_lightness_get(model, ctx, buf); + rc = light_lightness_get(model, ctx, buf); light_lightness_publish(model); - return; + return rc; } /* For Instantaneous Transition */ @@ -1402,9 +1453,10 @@ static void light_lightness_set(struct bt_mesh_model *model, light_lightness_get(model, ctx, buf); light_lightness_publish(model); light_lightness_actual_handler(state); + return 0; } -static void light_lightness_linear_get(struct bt_mesh_model *model, +static int light_lightness_linear_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1426,16 +1478,17 @@ static void light_lightness_linear_get(struct bt_mesh_model *model, } os_mbuf_free_chain(msg); + return 0; } -void light_lightness_linear_publish(struct bt_mesh_model *model) +int light_lightness_linear_publish(struct bt_mesh_model *model) { int err; struct os_mbuf *msg = model->pub->msg; struct light_lightness_state *state = model->user_data; if (model->pub->addr == BT_MESH_ADDR_UNASSIGNED) { - return; + return 0; } bt_mesh_model_msg_init(msg, @@ -1452,9 +1505,10 @@ void light_lightness_linear_publish(struct bt_mesh_model *model) if (err) { printk("bt_mesh_model_publish err %d\n", err); } + return err; } -static void light_lightness_linear_set_unack(struct bt_mesh_model *model, +static int light_lightness_linear_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1471,7 +1525,7 @@ static void light_lightness_linear_set_unack(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - return; + return 0; } switch (buf->om_len) { @@ -1482,13 +1536,13 @@ static void light_lightness_linear_set_unack(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -1504,7 +1558,7 @@ static void light_lightness_linear_set_unack(struct bt_mesh_model *model, light_lightness_linear_tt_values(state, tt, delay); } else { light_lightness_linear_publish(model); - return; + return 0; } /* For Instantaneous Transition */ @@ -1515,9 +1569,10 @@ static void light_lightness_linear_set_unack(struct bt_mesh_model *model, state->transition->just_started = true; light_lightness_linear_publish(model); light_lightness_linear_handler(state); + return 0; } -static void light_lightness_linear_set(struct bt_mesh_model *model, +static int light_lightness_linear_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1525,6 +1580,7 @@ static void light_lightness_linear_set(struct bt_mesh_model *model, uint16_t linear; int64_t now; struct light_lightness_state *state = model->user_data; + int rc; linear = net_buf_simple_pull_le16(buf); tid = net_buf_simple_pull_u8(buf); @@ -1534,8 +1590,7 @@ static void light_lightness_linear_set(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - light_lightness_linear_get(model, ctx, buf); - return; + return light_lightness_linear_get(model, ctx, buf); } switch (buf->om_len) { @@ -1546,13 +1601,13 @@ static void light_lightness_linear_set(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -1567,9 +1622,9 @@ static void light_lightness_linear_set(struct bt_mesh_model *model, if (state->target_linear != state->linear) { light_lightness_linear_tt_values(state, tt, delay); } else { - light_lightness_linear_get(model, ctx, buf); + rc = light_lightness_linear_get(model, ctx, buf); light_lightness_linear_publish(model); - return; + return rc; } /* For Instantaneous Transition */ @@ -1581,9 +1636,10 @@ static void light_lightness_linear_set(struct bt_mesh_model *model, light_lightness_linear_get(model, ctx, buf); light_lightness_linear_publish(model); light_lightness_linear_handler(state); + return 0; } -static void light_lightness_last_get(struct bt_mesh_model *model, +static int light_lightness_last_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1598,9 +1654,10 @@ static void light_lightness_last_get(struct bt_mesh_model *model, } os_mbuf_free_chain(msg); + return 0; } -static void light_lightness_default_get(struct bt_mesh_model *model, +static int light_lightness_default_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1616,9 +1673,10 @@ static void light_lightness_default_get(struct bt_mesh_model *model, } os_mbuf_free_chain(msg); + return 0; } -static void light_lightness_range_get(struct bt_mesh_model *model, +static int light_lightness_range_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1637,18 +1695,19 @@ static void light_lightness_range_get(struct bt_mesh_model *model, } os_mbuf_free_chain(msg); + return 0; } /* Light Lightness Setup Server message handlers */ -static void light_lightness_default_publish(struct bt_mesh_model *model) +static int light_lightness_default_publish(struct bt_mesh_model *model) { int err; struct os_mbuf *msg = model->pub->msg; struct light_lightness_state *state = model->user_data; if (model->pub->addr == BT_MESH_ADDR_UNASSIGNED) { - return; + return 0; } bt_mesh_model_msg_init(msg, @@ -1659,9 +1718,10 @@ static void light_lightness_default_publish(struct bt_mesh_model *model) if (err) { printk("bt_mesh_model_publish err %d\n", err); } + return err; } -static void light_lightness_default_set_unack(struct bt_mesh_model *model, +static int light_lightness_default_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1679,26 +1739,37 @@ static void light_lightness_default_set_unack(struct bt_mesh_model *model, save_on_flash(LIGHTNESS_TEMP_DEF_STATE); } - light_lightness_default_publish(model); + return light_lightness_default_publish(model); } -static void light_lightness_default_set(struct bt_mesh_model *model, +static int light_lightness_default_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { - light_lightness_default_set_unack(model, ctx, buf); - light_lightness_default_get(model, ctx, buf); - light_lightness_default_publish(model); + int rc; + rc = light_lightness_default_set_unack(model, ctx, buf); + if (rc) { + return rc; + } + rc = light_lightness_default_get(model, ctx, buf); + if (rc) { + return rc; + } + rc = light_lightness_default_publish(model); + if (rc) { + return rc; + } + return 0; } -static void light_lightness_range_publish(struct bt_mesh_model *model) +static int light_lightness_range_publish(struct bt_mesh_model *model) { int err; struct os_mbuf *msg = model->pub->msg; struct light_lightness_state *state = model->user_data; if (model->pub->addr == BT_MESH_ADDR_UNASSIGNED) { - return; + return 0; } bt_mesh_model_msg_init(msg, BT_MESH_MODEL_LIGHT_LIGHTNESS_RANGE_STATUS); @@ -1710,6 +1781,7 @@ static void light_lightness_range_publish(struct bt_mesh_model *model) if (err) { printk("bt_mesh_model_publish err %d\n", err); } + return err; } static bool light_lightness_range_setunack(struct bt_mesh_model *model, @@ -1748,27 +1820,36 @@ static bool light_lightness_range_setunack(struct bt_mesh_model *model, return true; } -static void light_lightness_range_set_unack(struct bt_mesh_model *model, +static int light_lightness_range_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { if (light_lightness_range_setunack(model, ctx, buf) == true) { - light_lightness_range_publish(model); + return light_lightness_range_publish(model); } + return 0; } -static void light_lightness_range_set(struct bt_mesh_model *model, +static int light_lightness_range_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { + int rc; if (light_lightness_range_setunack(model, ctx, buf) == true) { - light_lightness_range_get(model, ctx, buf); - light_lightness_range_publish(model); + rc = light_lightness_range_get(model, ctx, buf); + if (rc) { + return rc; + } + rc = light_lightness_range_publish(model); + if (rc) { + return rc; + } } + return 0; } /* Light Lightness Client message handlers */ -static void light_lightness_status(struct bt_mesh_model *model, +static int light_lightness_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1780,9 +1861,10 @@ static void light_lightness_status(struct bt_mesh_model *model, net_buf_simple_pull_le16(buf)); printk("Remaining Time = %02x\n", net_buf_simple_pull_u8(buf)); } + return 0; } -static void light_lightness_linear_status(struct bt_mesh_model *model, +static int light_lightness_linear_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1794,25 +1876,28 @@ static void light_lightness_linear_status(struct bt_mesh_model *model, net_buf_simple_pull_le16(buf)); printk("Remaining Time = %02x\n", net_buf_simple_pull_u8(buf)); } + return 0; } -static void light_lightness_last_status(struct bt_mesh_model *model, +static int light_lightness_last_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { printk("Acknownledgement from LIGHT_LIGHTNESS_SRV (Last)\n"); printk("Lightness = %04x\n", net_buf_simple_pull_le16(buf)); + return 0; } -static void light_lightness_default_status(struct bt_mesh_model *model, +static int light_lightness_default_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { printk("Acknownledgement from LIGHT_LIGHTNESS_SRV (Default)\n"); printk("Lightness = %04x\n", net_buf_simple_pull_le16(buf)); + return 0; } -static void light_lightness_range_status(struct bt_mesh_model *model, +static int light_lightness_range_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1820,10 +1905,11 @@ static void light_lightness_range_status(struct bt_mesh_model *model, printk("Status Code = %02x\n", net_buf_simple_pull_u8(buf)); printk("Range Min = %04x\n", net_buf_simple_pull_le16(buf)); printk("Range Max = %04x\n", net_buf_simple_pull_le16(buf)); + return 0; } /* Light CTL Server message handlers */ -static void light_ctl_get(struct bt_mesh_model *model, +static int light_ctl_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1846,16 +1932,17 @@ static void light_ctl_get(struct bt_mesh_model *model, } os_mbuf_free_chain(msg); + return 0; } -void light_ctl_publish(struct bt_mesh_model *model) +int light_ctl_publish(struct bt_mesh_model *model) { int err; struct os_mbuf *msg = model->pub->msg; struct light_ctl_state *state = model->user_data; if (model->pub->addr == BT_MESH_ADDR_UNASSIGNED) { - return; + return 0; } bt_mesh_model_msg_init(msg, BT_MESH_MODEL_LIGHT_CTL_STATUS); @@ -1877,9 +1964,10 @@ void light_ctl_publish(struct bt_mesh_model *model) if (err) { printk("bt_mesh_model_publish err %d\n", err); } + return err; } -static void light_ctl_set_unack(struct bt_mesh_model *model, +static int light_ctl_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1895,7 +1983,7 @@ static void light_ctl_set_unack(struct bt_mesh_model *model, tid = net_buf_simple_pull_u8(buf); if (temp < TEMP_MIN || temp > TEMP_MAX) { - return; + return 0; } now = k_uptime_get(); @@ -1903,7 +1991,7 @@ static void light_ctl_set_unack(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - return; + return 0; } switch (buf->om_len) { @@ -1914,13 +2002,13 @@ static void light_ctl_set_unack(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -1947,7 +2035,7 @@ static void light_ctl_set_unack(struct bt_mesh_model *model, light_ctl_tt_values(state, tt, delay); } else { light_ctl_publish(model); - return; + return 0; } /* For Instantaneous Transition */ @@ -1960,9 +2048,10 @@ static void light_ctl_set_unack(struct bt_mesh_model *model, state->transition->just_started = true; light_ctl_publish(model); light_ctl_handler(state); + return 0; } -static void light_ctl_set(struct bt_mesh_model *model, +static int light_ctl_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -1978,7 +2067,7 @@ static void light_ctl_set(struct bt_mesh_model *model, tid = net_buf_simple_pull_u8(buf); if (temp < TEMP_MIN || temp > TEMP_MAX) { - return; + return 0; } now = k_uptime_get(); @@ -1987,7 +2076,7 @@ static void light_ctl_set(struct bt_mesh_model *model, state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { light_ctl_get(model, ctx, buf); - return; + return 0; } switch (buf->om_len) { @@ -1998,13 +2087,13 @@ static void light_ctl_set(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -2032,7 +2121,7 @@ static void light_ctl_set(struct bt_mesh_model *model, } else { light_ctl_get(model, ctx, buf); light_ctl_publish(model); - return; + return 0; } /* For Instantaneous Transition */ @@ -2046,14 +2135,16 @@ static void light_ctl_set(struct bt_mesh_model *model, light_ctl_get(model, ctx, buf); light_ctl_publish(model); light_ctl_handler(state); + return 0; } -static void light_ctl_temp_range_get(struct bt_mesh_model *model, +static int light_ctl_temp_range_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { struct os_mbuf *msg = NET_BUF_SIMPLE(2 + 5 + 4); struct light_ctl_state *state = model->user_data; + int rc; state->status_code = RANGE_SUCCESSFULLY_UPDATED; @@ -2062,42 +2153,47 @@ static void light_ctl_temp_range_get(struct bt_mesh_model *model, net_buf_simple_add_le16(msg, state->temp_range_min); net_buf_simple_add_le16(msg, state->temp_range_max); - if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { + rc = bt_mesh_model_send(model, ctx, msg, NULL, NULL); + if (rc) { printk("Unable to send LightCTL Temp Range Status response\n"); } os_mbuf_free_chain(msg); + return rc; } -static void light_ctl_default_get(struct bt_mesh_model *model, +static int light_ctl_default_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { struct os_mbuf *msg = NET_BUF_SIMPLE(2 + 6 + 4); struct light_ctl_state *state = model->user_data; + int rc; bt_mesh_model_msg_init(msg, BT_MESH_MODEL_LIGHT_CTL_DEFAULT_STATUS); net_buf_simple_add_le16(msg, state->lightness_def); net_buf_simple_add_le16(msg, state->temp_def); net_buf_simple_add_le16(msg, state->delta_uv_def); - if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { + rc = bt_mesh_model_send(model, ctx, msg, NULL, NULL); + if (rc) { printk("Unable to send LightCTL Default Status response\n"); } os_mbuf_free_chain(msg); + return rc; } /* Light CTL Setup Server message handlers */ -static void light_ctl_default_publish(struct bt_mesh_model *model) +static int light_ctl_default_publish(struct bt_mesh_model *model) { int err; struct os_mbuf *msg = model->pub->msg; struct light_ctl_state *state = model->user_data; if (model->pub->addr == BT_MESH_ADDR_UNASSIGNED) { - return; + return 0; } bt_mesh_model_msg_init(msg, BT_MESH_MODEL_LIGHT_CTL_DEFAULT_STATUS); @@ -2109,6 +2205,7 @@ static void light_ctl_default_publish(struct bt_mesh_model *model) if (err) { printk("bt_mesh_model_publish err %d\n", err); } + return err; } static bool light_ctl_default_setunack(struct bt_mesh_model *model, @@ -2147,33 +2244,35 @@ static bool light_ctl_default_setunack(struct bt_mesh_model *model, return true; } -static void light_ctl_default_set_unack(struct bt_mesh_model *model, +static int light_ctl_default_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { if (light_ctl_default_setunack(model, ctx, buf) == true) { - light_ctl_default_publish(model); + return light_ctl_default_publish(model); } + return 0; } -static void light_ctl_default_set(struct bt_mesh_model *model, +static int light_ctl_default_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { if (light_ctl_default_setunack(model, ctx, buf) == true) { light_ctl_default_get(model, ctx, buf); - light_ctl_default_publish(model); + return light_ctl_default_publish(model); } + return 0; } -static void light_ctl_temp_range_publish(struct bt_mesh_model *model) +static int light_ctl_temp_range_publish(struct bt_mesh_model *model) { int err; struct os_mbuf *msg = model->pub->msg; struct light_ctl_state *state = model->user_data; if (model->pub->addr == BT_MESH_ADDR_UNASSIGNED) { - return; + return 0; } bt_mesh_model_msg_init(msg, BT_MESH_MODEL_LIGHT_CTL_TEMP_RANGE_STATUS); @@ -2185,6 +2284,7 @@ static void light_ctl_temp_range_publish(struct bt_mesh_model *model) if (err) { printk("bt_mesh_model_publish err %d\n", err); } + return err; } static bool light_ctl_temp_range_setunack(struct bt_mesh_model *model, @@ -2225,27 +2325,29 @@ static bool light_ctl_temp_range_setunack(struct bt_mesh_model *model, return true; } -static void light_ctl_temp_range_set_unack(struct bt_mesh_model *model, +static int light_ctl_temp_range_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { if (light_ctl_temp_range_setunack(model, ctx, buf) == true) { - light_ctl_temp_range_publish(model); + return light_ctl_temp_range_publish(model); } + return 0; } -static void light_ctl_temp_range_set(struct bt_mesh_model *model, +static int light_ctl_temp_range_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { if (light_ctl_temp_range_setunack(model, ctx, buf) == true) { light_ctl_temp_range_get(model, ctx, buf); - light_ctl_temp_range_publish(model); + return light_ctl_temp_range_publish(model); } + return 0; } /* Light CTL Client message handlers */ -static void light_ctl_status(struct bt_mesh_model *model, +static int light_ctl_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -2261,9 +2363,10 @@ static void light_ctl_status(struct bt_mesh_model *model, net_buf_simple_pull_le16(buf)); printk("Remaining Time = %02x\n", net_buf_simple_pull_u8(buf)); } + return 0; } -static void light_ctl_temp_range_status(struct bt_mesh_model *model, +static int light_ctl_temp_range_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -2271,9 +2374,10 @@ static void light_ctl_temp_range_status(struct bt_mesh_model *model, printk("Status Code = %02x\n", net_buf_simple_pull_u8(buf)); printk("Range Min = %04x\n", net_buf_simple_pull_le16(buf)); printk("Range Max = %04x\n", net_buf_simple_pull_le16(buf)); + return 0; } -static void light_ctl_temp_status(struct bt_mesh_model *model, +static int light_ctl_temp_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -2290,9 +2394,10 @@ static void light_ctl_temp_status(struct bt_mesh_model *model, net_buf_simple_pull_le16(buf)); printk("Remaining Time = %02x\n", net_buf_simple_pull_u8(buf)); } + return 0; } -static void light_ctl_default_status(struct bt_mesh_model *model, +static int light_ctl_default_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -2300,10 +2405,11 @@ static void light_ctl_default_status(struct bt_mesh_model *model, printk("Lightness = %04x\n", net_buf_simple_pull_le16(buf)); printk("Temperature = %04x\n", net_buf_simple_pull_le16(buf)); printk("Delta UV = %04x\n", net_buf_simple_pull_le16(buf)); + return 0; } /* Light CTL Temp. Server message handlers */ -static void light_ctl_temp_get(struct bt_mesh_model *model, +static int light_ctl_temp_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -2326,16 +2432,17 @@ static void light_ctl_temp_get(struct bt_mesh_model *model, } os_mbuf_free_chain(msg); + return 0; } -void light_ctl_temp_publish(struct bt_mesh_model *model) +int light_ctl_temp_publish(struct bt_mesh_model *model) { int err; struct os_mbuf *msg = model->pub->msg; struct light_ctl_state *state = model->user_data; if (model->pub->addr == BT_MESH_ADDR_UNASSIGNED) { - return; + return 0; } bt_mesh_model_msg_init(msg, BT_MESH_MODEL_LIGHT_CTL_TEMP_STATUS); @@ -2353,9 +2460,10 @@ void light_ctl_temp_publish(struct bt_mesh_model *model) if (err) { printk("bt_mesh_model_publish err %d\n", err); } + return err; } -static void light_ctl_temp_set_unack(struct bt_mesh_model *model, +static int light_ctl_temp_set_unack(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -2370,7 +2478,7 @@ static void light_ctl_temp_set_unack(struct bt_mesh_model *model, tid = net_buf_simple_pull_u8(buf); if (temp < TEMP_MIN || temp > TEMP_MAX) { - return; + return 0; } now = k_uptime_get(); @@ -2378,7 +2486,7 @@ static void light_ctl_temp_set_unack(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - return; + return 0; } switch (buf->om_len) { @@ -2389,13 +2497,13 @@ static void light_ctl_temp_set_unack(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -2420,7 +2528,7 @@ static void light_ctl_temp_set_unack(struct bt_mesh_model *model, light_ctl_temp_tt_values(state, tt, delay); } else { light_ctl_temp_publish(model); - return; + return 0; } /* For Instantaneous Transition */ @@ -2432,9 +2540,10 @@ static void light_ctl_temp_set_unack(struct bt_mesh_model *model, state->transition->just_started = true; light_ctl_temp_publish(model); light_ctl_temp_handler(state); + return 0; } -static void light_ctl_temp_set(struct bt_mesh_model *model, +static int light_ctl_temp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf) { @@ -2449,7 +2558,7 @@ static void light_ctl_temp_set(struct bt_mesh_model *model, tid = net_buf_simple_pull_u8(buf); if (temp < TEMP_MIN || temp > TEMP_MAX) { - return; + return 0; } now = k_uptime_get(); @@ -2457,8 +2566,7 @@ static void light_ctl_temp_set(struct bt_mesh_model *model, state->last_src_addr == ctx->addr && state->last_dst_addr == ctx->recv_dst && (now - state->last_msg_timestamp <= K_SECONDS(6))) { - light_ctl_temp_get(model, ctx, buf); - return; + return light_ctl_temp_get(model, ctx, buf); } switch (buf->om_len) { @@ -2469,13 +2577,13 @@ static void light_ctl_temp_set(struct bt_mesh_model *model, case 0x02: /* Optional fields are available */ tt = net_buf_simple_pull_u8(buf); if ((tt & 0x3F) == 0x3F) { - return; + return 0; } delay = net_buf_simple_pull_u8(buf); break; default: - return; + return 0; } *ptr_counter = 0; @@ -2501,7 +2609,7 @@ static void light_ctl_temp_set(struct bt_mesh_model *model, } else { light_ctl_temp_get(model, ctx, buf); light_ctl_temp_publish(model); - return; + return 0; } /* For Instantaneous Transition */ @@ -2514,6 +2622,7 @@ static void light_ctl_temp_set(struct bt_mesh_model *model, light_ctl_temp_get(model, ctx, buf); light_ctl_temp_publish(model); light_ctl_temp_handler(state); + return 0; } /* message handlers (End) */ diff --git a/apps/blemesh_models_example_2/src/device_composition.h b/apps/blemesh_models_example_2/src/device_composition.h index d0f054ee2..1b5bf5f72 100644 --- a/apps/blemesh_models_example_2/src/device_composition.h +++ b/apps/blemesh_models_example_2/src/device_composition.h @@ -167,11 +167,11 @@ extern struct bt_mesh_model s0_models[]; extern const struct bt_mesh_comp comp; -void gen_onoff_publish(struct bt_mesh_model *model); -void gen_level_publish(struct bt_mesh_model *model); -void light_lightness_publish(struct bt_mesh_model *model); -void light_lightness_linear_publish(struct bt_mesh_model *model); -void light_ctl_publish(struct bt_mesh_model *model); -void light_ctl_temp_publish(struct bt_mesh_model *model); +int gen_onoff_publish(struct bt_mesh_model *model); +int gen_level_publish(struct bt_mesh_model *model); +int light_lightness_publish(struct bt_mesh_model *model); +int light_lightness_linear_publish(struct bt_mesh_model *model); +int light_ctl_publish(struct bt_mesh_model *model); +int light_ctl_temp_publish(struct bt_mesh_model *model); #endif