net: lwm2m: JSON dynamic Resource instance allocation
Integrated dynamic resouce instance allocation to JSON. Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
This commit is contained in:
parent
7b3a1f31fe
commit
dde5c16709
1 changed files with 7 additions and 53 deletions
|
@ -910,7 +910,7 @@ int do_write_op_json(struct lwm2m_message *msg)
|
|||
struct lwm2m_engine_res_inst *res_inst = NULL;
|
||||
struct lwm2m_obj_path orig_path;
|
||||
struct json_in_formatter_data fd;
|
||||
int ret = 0, index;
|
||||
int ret = 0;
|
||||
uint8_t value[TOKEN_BUF_LEN];
|
||||
uint8_t base_name[MAX_RESOURCE_LEN];
|
||||
uint8_t full_name[MAX_RESOURCE_LEN];
|
||||
|
@ -1011,60 +1011,14 @@ int do_write_op_json(struct lwm2m_message *msg)
|
|||
break;
|
||||
}
|
||||
|
||||
obj_field = lwm2m_get_engine_obj_field(
|
||||
obj_inst->obj,
|
||||
msg->path.res_id);
|
||||
/*
|
||||
* if obj_field is not found,
|
||||
* treat as an optional resource
|
||||
*/
|
||||
if (!obj_field) {
|
||||
ret = -ENOENT;
|
||||
break;
|
||||
ret = lwm2m_engine_validate_write_access(msg, obj_inst, &obj_field);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: support BOOTSTRAP WRITE where optional
|
||||
* resources are ignored
|
||||
*/
|
||||
|
||||
if (!LWM2M_HAS_PERM(obj_field, LWM2M_PERM_W) &&
|
||||
!lwm2m_engine_bootstrap_override(msg->ctx, &msg->path)) {
|
||||
ret = -EPERM;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!obj_inst->resources ||
|
||||
obj_inst->resource_count == 0U) {
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
for (index = 0; index < obj_inst->resource_count;
|
||||
index++) {
|
||||
if (obj_inst->resources[index].res_id ==
|
||||
msg->path.res_id) {
|
||||
res = &obj_inst->resources[index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!res) {
|
||||
ret = -ENOENT;
|
||||
break;
|
||||
}
|
||||
|
||||
for (index = 0; index < res->res_inst_count; index++) {
|
||||
if (res->res_instances[index].res_inst_id ==
|
||||
msg->path.res_inst_id) {
|
||||
res_inst = &res->res_instances[index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!res_inst) {
|
||||
ret = -ENOENT;
|
||||
break;
|
||||
ret = lwm2m_engine_get_create_res_inst(&msg->path, &res, &res_inst);
|
||||
if (ret < 0) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* Write the resource value */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue