From 9dcbbdb3e23bb85b632aea0dd3693b5c25c2e273 Mon Sep 17 00:00:00 2001 From: Robert Chou Date: Wed, 15 Nov 2017 16:20:05 +0800 Subject: [PATCH] net: lwm2m: fix sending packet w/o token setup when error Token is missing when we jump to the error and token is not yet setup. To correct it, we grab the token from the input packet at the beginning of the handle_request() Signed-off-by: Robert Chou --- subsys/net/lib/lwm2m/lwm2m_engine.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 6c805615692..f0b3ad3c20b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -2421,6 +2421,13 @@ static int handle_request(struct coap_packet *request, code = coap_header_get_code(in.in_cpkt); + /* setup response token */ + tkl = coap_header_get_token(in.in_cpkt, token); + if (tkl) { + msg->tkl = tkl; + msg->token = token; + } + /* parse the URL path into components */ r = coap_find_options(in.in_cpkt, COAP_OPTION_URI_PATH, options, 4); if (r <= 0) { @@ -2529,13 +2536,6 @@ static int handle_request(struct coap_packet *request, break; } - /* setup response token */ - tkl = coap_header_get_token(in.in_cpkt, token); - if (tkl) { - msg->tkl = tkl; - msg->token = token; - } - /* setup incoming data */ in.frag = coap_packet_get_payload(in.in_cpkt, &in.offset, &in.payload_len);