Skip to content

Commit 9777ba7

Browse files
Juha Heiskanencarlescufi
authored andcommitted
net: lwm2m: SenML JSON dynamic Resource instance allocation
Integrated dynamic resouce instance allocation to SenML JSON. Signed-off-by: Juha Heiskanen <[email protected]>
1 parent 88ec25b commit 9777ba7

File tree

1 file changed

+5
-35
lines changed

1 file changed

+5
-35
lines changed

subsys/net/lib/lwm2m/lwm2m_rw_senml_json.c

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,43 +1119,13 @@ static int lwm2m_senml_write_operation(struct lwm2m_message *msg, struct json_in
11191119
return ret;
11201120
}
11211121

1122-
obj_field = lwm2m_get_engine_obj_field(obj_inst->obj, msg->path.res_id);
1123-
/*
1124-
* if obj_field is not found,
1125-
* treat as an optional resource
1126-
*/
1127-
if (!obj_field) {
1128-
return -ENOENT;
1129-
}
1130-
1131-
if (!LWM2M_HAS_PERM(obj_field, LWM2M_PERM_W) &&
1132-
!lwm2m_engine_bootstrap_override(msg->ctx, &msg->path)) {
1133-
return -EPERM;
1134-
}
1135-
1136-
if (!obj_inst->resources || obj_inst->resource_count == 0U) {
1137-
return -EINVAL;
1138-
}
1139-
1140-
for (int index = 0; index < obj_inst->resource_count; index++) {
1141-
if (obj_inst->resources[index].res_id == msg->path.res_id) {
1142-
res = &obj_inst->resources[index];
1143-
break;
1144-
}
1145-
}
1146-
1147-
if (!res) {
1148-
return -ENOENT;
1149-
}
1150-
1151-
for (int index = 0; index < res->res_inst_count; index++) {
1152-
if (res->res_instances[index].res_inst_id == msg->path.res_inst_id) {
1153-
res_inst = &res->res_instances[index];
1154-
break;
1155-
}
1122+
ret = lwm2m_engine_validate_write_access(msg, obj_inst, &obj_field);
1123+
if (ret < 0) {
1124+
return ret;
11561125
}
11571126

1158-
if (!res_inst) {
1127+
ret = lwm2m_engine_get_create_res_inst(&msg->path, &res, &res_inst);
1128+
if (ret < 0) {
11591129
return -ENOENT;
11601130
}
11611131

0 commit comments

Comments
 (0)