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-02-14 06:15:17 -08:00 committed by Anas Nashif
commit 60088b18d4

View file

@ -3182,17 +3182,18 @@ int lwm2m_perform_read_op(struct lwm2m_message *msg, uint16_t content_format)
uint8_t num_read = 0U;
if (msg->path.level >= 2U) {
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 == 1U) {
/* 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,