net: lwm2m: Resource Instance level read access.
Makes possible to read a single resource instance at a time with plaint text, JSON and TLV content formats. Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
This commit is contained in:
parent
34acbceef5
commit
2231287e27
3 changed files with 30 additions and 5 deletions
|
@ -2399,6 +2399,12 @@ static int lwm2m_read_handler(struct lwm2m_engine_obj_inst *obj_inst,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IS_ENABLED(CONFIG_LWM2M_VERSION_1_1) &&
|
||||||
|
msg->path.level == LWM2M_PATH_LEVEL_RESOURCE_INST &&
|
||||||
|
msg->path.res_inst_id != res->res_instances[i].res_inst_id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (res->res_inst_count > 1) {
|
if (res->res_inst_count > 1) {
|
||||||
msg->path.res_inst_id =
|
msg->path.res_inst_id =
|
||||||
res->res_instances[i].res_inst_id;
|
res->res_instances[i].res_inst_id;
|
||||||
|
@ -3496,8 +3502,15 @@ int lwm2m_perform_read_op(struct lwm2m_message *msg, uint16_t content_format)
|
||||||
memcpy(&msg->path, &temp_path, sizeof(temp_path));
|
memcpy(&msg->path, &temp_path, sizeof(temp_path));
|
||||||
|
|
||||||
/* did not read anything even if we should have - on single item */
|
/* did not read anything even if we should have - on single item */
|
||||||
if (ret == 0 && num_read == 0U && msg->path.level >= LWM2M_PATH_LEVEL_RESOURCE) {
|
if (ret == 0 && num_read == 0U) {
|
||||||
return -ENOENT;
|
if (msg->path.level == LWM2M_PATH_LEVEL_RESOURCE) {
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IS_ENABLED(CONFIG_LWM2M_VERSION_1_1) &&
|
||||||
|
msg->path.level == LWM2M_PATH_LEVEL_RESOURCE_INST) {
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -382,6 +382,12 @@ static int put_end_ri(struct lwm2m_output_context *out,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Skip writing Multiple Resource TLV if path level is 4 */
|
||||||
|
if (IS_ENABLED(CONFIG_LWM2M_VERSION_1_1) &&
|
||||||
|
path->level == LWM2M_PATH_LEVEL_RESOURCE_INST) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return put_end_tlv(out, fd->mark_pos_ri, &fd->writer_flags,
|
return put_end_tlv(out, fd->mark_pos_ri, &fd->writer_flags,
|
||||||
WRITER_RESOURCE_INSTANCE,
|
WRITER_RESOURCE_INSTANCE,
|
||||||
OMA_TLV_TYPE_MULTI_RESOURCE, path->res_id);
|
OMA_TLV_TYPE_MULTI_RESOURCE, path->res_id);
|
||||||
|
|
|
@ -421,9 +421,15 @@ const struct lwm2m_reader plain_text_reader = {
|
||||||
|
|
||||||
int do_read_op_plain_text(struct lwm2m_message *msg, int content_format)
|
int do_read_op_plain_text(struct lwm2m_message *msg, int content_format)
|
||||||
{
|
{
|
||||||
/* Plain text can only return single resource */
|
/* Plain text can only return single resource (instance) */
|
||||||
if (msg->path.level != 3U) {
|
if (msg->path.level < LWM2M_PATH_LEVEL_RESOURCE) {
|
||||||
return -EPERM; /* NOT_ALLOWED */
|
return -EPERM;
|
||||||
|
} else if (msg->path.level > LWM2M_PATH_LEVEL_RESOURCE) {
|
||||||
|
if (!IS_ENABLED(CONFIG_LWM2M_VERSION_1_1)) {
|
||||||
|
return -ENOENT;
|
||||||
|
} else if (msg->path.level > LWM2M_PATH_LEVEL_RESOURCE_INST) {
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lwm2m_perform_read_op(msg, content_format);
|
return lwm2m_perform_read_op(msg, content_format);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue