Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions subsys/net/lib/lwm2m/lwm2m_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ struct lwm2m_block_context {
uint8_t token[8];
uint8_t tkl;
bool last_block : 1;
uint16_t res_id;
};

struct lwm2m_output_context {
Expand Down
64 changes: 37 additions & 27 deletions subsys/net/lib/lwm2m/lwm2m_rw_oma_tlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -935,23 +935,53 @@ static int do_write_op_tlv_item(struct lwm2m_message *msg)
return ret;
}

static int write_tlv_resource(struct lwm2m_message *msg, struct oma_tlv *tlv)
{
int ret;

if (msg->in.block_ctx) {
msg->in.block_ctx->res_id = tlv->id;
}

msg->path.res_id = tlv->id;
msg->path.level = 3U;
ret = do_write_op_tlv_item(msg);

/*
* ignore errors for CREATE op
* for OP_CREATE and BOOTSTRAP WRITE: errors on
* optional resources are ignored (ENOTSUP)
*/
if (ret < 0 &&
!((ret == -ENOTSUP) &&
(msg->ctx->bootstrap_mode ||
msg->operation == LWM2M_OP_CREATE))) {
return ret;
}

return 0;
}

int do_write_op_tlv(struct lwm2m_message *msg)
{
struct lwm2m_engine_obj_inst *obj_inst = NULL;
size_t len;
struct oma_tlv tlv;
int ret;

/* In case of Firmware object Package resource go directly to the
/* In case of block transfer go directly to the
* message processing - consecutive blocks will not carry the TLV
* header.
*/
if (msg->in.block_ctx != NULL && msg->in.block_ctx->ctx.current > 0 &&
msg->path.obj_id == 5 && msg->path.res_id == 0) {
if (msg->in.block_ctx != NULL && msg->in.block_ctx->ctx.current > 0) {
msg->path.res_id = msg->in.block_ctx->res_id;
msg->path.level = 3U;
ret = do_write_op_tlv_item(msg);
if (ret < 0) {
return ret;
}

return 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "return 0;" seems to cause a problem.
If the current packet contains writes to other resources in the object, those will not be processed. Only the first item is written, and function returns without processing the rest.
If I remove the "return 0", it seems to resolve my problem and the other writes are processed. However, that "return 0" was specifically added for a reason, so I am not confident that is the correct fix.

}

while (true) {
Expand Down Expand Up @@ -995,36 +1025,16 @@ int do_write_op_tlv(struct lwm2m_message *msg)
continue;
}

msg->path.res_id = tlv2.id;
msg->path.level = 3U;
ret = do_write_op_tlv_item(msg);
/*
* ignore errors for CREATE op
* for OP_CREATE and BOOTSTRAP WRITE: errors on
* optional resources are ignored (ENOTSUP)
*/
if (ret < 0 &&
!((ret == -ENOTSUP) &&
(msg->ctx->bootstrap_mode ||
msg->operation == LWM2M_OP_CREATE))) {
ret = write_tlv_resource(msg, &tlv2);
if (ret) {
return ret;
}

pos += len2;
}
} else if (tlv.type == OMA_TLV_TYPE_RESOURCE) {
msg->path.res_id = tlv.id;
msg->path.level = 3U;
ret = do_write_op_tlv_item(msg);
/*
* ignore errors for CREATE op
* for OP_CREATE and BOOTSTRAP WRITE: errors on optional
* resources are ignored (ENOTSUP)
*/
if (ret < 0 &&
!((ret == -ENOTSUP) &&
(msg->ctx->bootstrap_mode ||
msg->operation == LWM2M_OP_CREATE))) {
ret = write_tlv_resource(msg, &tlv);
if (ret) {
return ret;
}
} else {
Expand Down