net: lwm2m: Fix Read operation for /object

Read operation must return empty payload when read /object_id
if there is no created object instances.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
This commit is contained in:
Juha Heiskanen 2022-03-21 03:52:11 -07:00 committed by Carles Cufí
commit 0c6ea8eec4

View file

@ -3838,17 +3838,18 @@ int lwm2m_perform_read_op(struct lwm2m_message *msg, uint16_t content_format)
uint8_t num_read = 0U;
if (msg->path.level >= LWM2M_PATH_LEVEL_OBJECT_INST) {
obj_inst = get_engine_obj_inst(msg->path.obj_id,
msg->path.obj_inst_id);
obj_inst = get_engine_obj_inst(msg->path.obj_id, msg->path.obj_inst_id);
if (!obj_inst) {
/* When Object instace is indicated error have to be reported */
return -ENOENT;
}
} else if (msg->path.level == LWM2M_PATH_LEVEL_OBJECT) {
/* find first obj_inst with path's obj_id */
/* find first obj_inst with path's obj_id.
* Path level 1 can accept NULL. It define empty payload to response.
*/
obj_inst = next_engine_obj_inst(msg->path.obj_id, -1);
}
if (!obj_inst) {
return -ENOENT;
}
/* set output content-format */
ret = coap_append_option_int(msg->out.out_cpkt,
COAP_OPTION_CONTENT_FORMAT,