diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 37695df8d9e..e293ddfc429 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -6155,6 +6155,7 @@ static int do_send_op(struct lwm2m_message *msg, uint16_t content_format, } } +#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) static int do_send_reply_cb(const struct coap_packet *response, struct coap_reply *reply, const struct sockaddr *from) @@ -6182,10 +6183,12 @@ static void do_send_timeout_cb(struct lwm2m_message *msg) LOG_WRN("Send Timeout"); } +#endif int lwm2m_engine_send(struct lwm2m_ctx *ctx, char const *path_list[], uint8_t path_list_size, bool confirmation_request) { +#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) struct lwm2m_message *msg; int ret; uint16_t content_format; @@ -6196,6 +6199,11 @@ int lwm2m_engine_send(struct lwm2m_ctx *ctx, char const *path_list[], uint8_t pa sys_slist_t lwm2m_path_list; sys_slist_t lwm2m_path_free_list; + if (lwm2m_server_get_mute_send(ctx->srv_obj_inst)) { + LOG_WRN("Send operation is muted by server"); + return -EPERM; + } + /* Init list */ lwm2m_engine_path_list_init(&lwm2m_path_list, &lwm2m_path_free_list, lwm2m_path_list_buf, CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE); @@ -6278,6 +6286,10 @@ int lwm2m_engine_send(struct lwm2m_ctx *ctx, char const *path_list[], uint8_t pa cleanup: lwm2m_reset_message(msg, true); return ret; +#else + LOG_WRN("LwM2M send is only supported for CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1"); + return -ENOTSUP; +#endif } SYS_INIT(lwm2m_engine_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.h b/subsys/net/lib/lwm2m/lwm2m_engine.h index f0c8c1c1de1..eb35a2d61d8 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.h +++ b/subsys/net/lib/lwm2m/lwm2m_engine.h @@ -166,6 +166,10 @@ int32_t lwm2m_server_get_pmin(uint16_t obj_inst_id); int32_t lwm2m_server_get_pmax(uint16_t obj_inst_id); int lwm2m_server_short_id_to_inst(uint16_t short_id); +#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) +bool lwm2m_server_get_mute_send(uint16_t obj_inst_id); +#endif + #if defined(CONFIG_LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT) void lwm2m_firmware_set_update_state_inst(uint16_t obj_inst_id, uint8_t state); void lwm2m_firmware_set_update_result_inst(uint16_t obj_inst_id, uint8_t result); diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_server.c b/subsys/net/lib/lwm2m/lwm2m_obj_server.c index f1507bdce62..18b45a5b7be 100644 --- a/subsys/net/lib/lwm2m/lwm2m_obj_server.c +++ b/subsys/net/lib/lwm2m/lwm2m_obj_server.c @@ -82,6 +82,9 @@ static uint8_t server_flag_disabled[MAX_INSTANCE_COUNT]; static uint32_t disabled_timeout[MAX_INSTANCE_COUNT]; static uint8_t server_flag_store_notify[MAX_INSTANCE_COUNT]; static char transport_binding[MAX_INSTANCE_COUNT][TRANSPORT_BINDING_LEN]; +#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) +static bool mute_send[MAX_INSTANCE_COUNT]; +#endif static struct lwm2m_engine_obj server; static struct lwm2m_engine_obj_field fields[] = { @@ -156,6 +159,18 @@ static int bootstrap_trigger_cb(uint16_t obj_inst_id, return -EPERM; #endif } + +bool lwm2m_server_get_mute_send(uint16_t obj_inst_id) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(inst); i++) { + if (inst[i].obj && inst[i].obj_inst_id == obj_inst_id) { + return mute_send[i]; + } + } + return false; +} #endif /* defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) */ @@ -252,6 +267,10 @@ static struct lwm2m_engine_obj_inst *server_create(uint16_t obj_inst_id) default_min_period[index] = CONFIG_LWM2M_SERVER_DEFAULT_PMIN; default_max_period[index] = CONFIG_LWM2M_SERVER_DEFAULT_PMAX; disabled_timeout[index] = 86400U; +#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) + mute_send[index] = false; +#endif + lwm2m_engine_get_binding(transport_binding[index]); (void)memset(res[index], 0, @@ -312,7 +331,8 @@ static struct lwm2m_engine_obj_inst *server_create(uint16_t obj_inst_id) res_inst[index], j); INIT_OBJ_RES_OPTDATA(SERVER_SMS_TRIGGER_ID, res[index], i, res_inst[index], j); INIT_OBJ_RES_OPTDATA(SERVER_PREFERRED_TRANSPORT_ID, res[index], i, res_inst[index], j); - INIT_OBJ_RES_OPTDATA(SERVER_MUTE_SEND_ID, res[index], i, res_inst[index], j); + INIT_OBJ_RES_DATA(SERVER_MUTE_SEND_ID, res[index], i, res_inst[index], j, &mute_send[index], + sizeof(bool)); #endif /* defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) */ inst[index].resources = res[index];