From cf513451eb160cc141ba306e308fb4ec1f521715 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Tue, 24 Oct 2023 15:34:51 +0300 Subject: [PATCH] net: lwm2m: Keep user_data between blocks CoAP reply structure user_data should be kept between ongoing blocks, so that callbacks for LwM2M send continue to work on blockwise transfers. Fixes #64290 Signed-off-by: Seppo Takalo --- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index a7d4492b981d3c..ed5f28aabdb33a 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -304,6 +304,9 @@ STATIC int build_msg_block_for_send(struct lwm2m_message *msg, uint16_t block_nu } msg->cpkt.hdr_len = msg->body_encode_buffer.hdr_len; } else { + /* Keep user data between blocks */ + void *user_data = msg->reply ? msg->reply->user_data : NULL; + /* reuse message for next block. Copy token from the new query to allow * CoAP clients to use new token for every query of ongoing transaction */ @@ -323,6 +326,9 @@ STATIC int build_msg_block_for_send(struct lwm2m_message *msg, uint16_t block_nu LOG_ERR("Unable to init lwm2m message for next block!"); return ret; } + if (msg->reply) { + msg->reply->user_data = user_data; + } } /* copy the options */