From ebb90c5184cf296d324685862bd8a02a02e6bd23 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 24 Aug 2023 16:42:00 +0300 Subject: [PATCH] net: lwm2m: Fix composite read on SenML-CBOR Composite read was incorrectly trying to parse CoAP packet instead of payload of the packet. Signed-off-by: Seppo Takalo --- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 6 ------ subsys/net/lib/lwm2m/lwm2m_message_handling.h | 6 +++++- subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c | 5 ++++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index df940cf4adba82..06cc1b5ecf83ef 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -417,12 +417,6 @@ STATIC int prepare_msg_for_send(struct lwm2m_message *msg) #endif -bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg) -{ - return msg->block_send; -} - - void lwm2m_engine_context_close(struct lwm2m_ctx *client_ctx) { struct lwm2m_message *msg; diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.h b/subsys/net/lib/lwm2m/lwm2m_message_handling.h index fd6c4470d840be..c41fbbac0eeef0 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.h +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.h @@ -75,6 +75,10 @@ enum coap_block_size lwm2m_default_block_size(void); int lwm2m_parse_peerinfo(char *url, struct lwm2m_ctx *client_ctx, bool is_firmware_uri); void lwm2m_clear_block_contexts(void); -bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg); + +static inline bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg) +{ + return msg->block_send; +} #endif /* LWM2M_MESSAGE_HANDLING_H */ diff --git a/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c b/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c index d62af88200be41..15dc9a9451ee36 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c +++ b/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c @@ -836,12 +836,15 @@ static uint8_t parse_composite_read_paths(struct lwm2m_message *msg, uint_fast8_t dret; int len; int ret; + char *payload; + uint16_t in_len; setup_in_fmt_data(msg); fd = engine_get_in_user_data(&msg->in); + payload = (char *)coap_packet_get_payload(msg->in.in_cpkt, &in_len); - dret = cbor_decode_lwm2m_senml(ICTX_BUF_R_REGION(&msg->in), &fd->dcd, &isize); + dret = cbor_decode_lwm2m_senml(payload, in_len, &fd->dcd, &isize); if (dret != ZCBOR_SUCCESS) { __ASSERT_NO_MSG(false);