Skip to content

Commit d2ee8f4

Browse files
committed
net: lwm2m: Only parse TLV from the first block
This was already implemented for firmware update packages. For other opaque resources it failed to determine the target resource id, which is now stored in the block_context. Signed-off-by: Jan Buenker <jan.buenker@grandcentrix.net>
1 parent 77a751e commit d2ee8f4

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

subsys/net/lib/lwm2m/lwm2m_object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ struct lwm2m_block_context {
414414
uint8_t token[8];
415415
uint8_t tkl;
416416
bool last_block : 1;
417+
uint16_t res_id;
417418
};
418419

419420
struct lwm2m_output_context {

subsys/net/lib/lwm2m/lwm2m_rw_oma_tlv.c

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -935,23 +935,53 @@ static int do_write_op_tlv_item(struct lwm2m_message *msg)
935935
return ret;
936936
}
937937

938+
static int write_tlv_resource(struct lwm2m_message *msg, struct oma_tlv *tlv)
939+
{
940+
int ret;
941+
942+
if (msg->in.block_ctx) {
943+
msg->in.block_ctx->res_id = tlv->id;
944+
}
945+
946+
msg->path.res_id = tlv->id;
947+
msg->path.level = 3U;
948+
ret = do_write_op_tlv_item(msg);
949+
950+
/*
951+
* ignore errors for CREATE op
952+
* for OP_CREATE and BOOTSTRAP WRITE: errors on
953+
* optional resources are ignored (ENOTSUP)
954+
*/
955+
if (ret < 0 &&
956+
!((ret == -ENOTSUP) &&
957+
(msg->ctx->bootstrap_mode ||
958+
msg->operation == LWM2M_OP_CREATE))) {
959+
return ret;
960+
}
961+
962+
return 0;
963+
}
964+
938965
int do_write_op_tlv(struct lwm2m_message *msg)
939966
{
940967
struct lwm2m_engine_obj_inst *obj_inst = NULL;
941968
size_t len;
942969
struct oma_tlv tlv;
943970
int ret;
944971

945-
/* In case of Firmware object Package resource go directly to the
972+
/* In case of block transfer go directly to the
946973
* message processing - consecutive blocks will not carry the TLV
947974
* header.
948975
*/
949-
if (msg->in.block_ctx != NULL && msg->in.block_ctx->ctx.current > 0 &&
950-
msg->path.obj_id == 5 && msg->path.res_id == 0) {
976+
if (msg->in.block_ctx != NULL && msg->in.block_ctx->ctx.current > 0) {
977+
msg->path.res_id = msg->in.block_ctx->res_id;
978+
msg->path.level = 3U;
951979
ret = do_write_op_tlv_item(msg);
952980
if (ret < 0) {
953981
return ret;
954982
}
983+
984+
return 0;
955985
}
956986

957987
while (true) {
@@ -995,36 +1025,16 @@ int do_write_op_tlv(struct lwm2m_message *msg)
9951025
continue;
9961026
}
9971027

998-
msg->path.res_id = tlv2.id;
999-
msg->path.level = 3U;
1000-
ret = do_write_op_tlv_item(msg);
1001-
/*
1002-
* ignore errors for CREATE op
1003-
* for OP_CREATE and BOOTSTRAP WRITE: errors on
1004-
* optional resources are ignored (ENOTSUP)
1005-
*/
1006-
if (ret < 0 &&
1007-
!((ret == -ENOTSUP) &&
1008-
(msg->ctx->bootstrap_mode ||
1009-
msg->operation == LWM2M_OP_CREATE))) {
1028+
ret = write_tlv_resource(msg, &tlv2);
1029+
if (ret) {
10101030
return ret;
10111031
}
10121032

10131033
pos += len2;
10141034
}
10151035
} else if (tlv.type == OMA_TLV_TYPE_RESOURCE) {
1016-
msg->path.res_id = tlv.id;
1017-
msg->path.level = 3U;
1018-
ret = do_write_op_tlv_item(msg);
1019-
/*
1020-
* ignore errors for CREATE op
1021-
* for OP_CREATE and BOOTSTRAP WRITE: errors on optional
1022-
* resources are ignored (ENOTSUP)
1023-
*/
1024-
if (ret < 0 &&
1025-
!((ret == -ENOTSUP) &&
1026-
(msg->ctx->bootstrap_mode ||
1027-
msg->operation == LWM2M_OP_CREATE))) {
1036+
ret = write_tlv_resource(msg, &tlv);
1037+
if (ret) {
10281038
return ret;
10291039
}
10301040
} else {

0 commit comments

Comments
 (0)