From ad38dd9a6fee54b1c3d667e6bac09539645abef9 Mon Sep 17 00:00:00 2001 From: Ken Bannister <kb2ma@runbox.com> Date: Mon, 1 Oct 2018 01:02:54 -0400 Subject: [PATCH] net/nanocoap: fix non-confirmable response type --- sys/net/application_layer/nanocoap/nanocoap.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sys/net/application_layer/nanocoap/nanocoap.c b/sys/net/application_layer/nanocoap/nanocoap.c index 528a655a80..c958201f9c 100644 --- a/sys/net/application_layer/nanocoap/nanocoap.c +++ b/sys/net/application_layer/nanocoap/nanocoap.c @@ -370,8 +370,16 @@ ssize_t coap_build_reply(coap_pkt_t *pkt, unsigned code, return -ENOSPC; } - /* if code is COAP_CODE_EMPTY (zero), use RST as type, else RESP */ - unsigned type = code ? COAP_RESP : COAP_RST; + /* if code is COAP_CODE_EMPTY (zero), assume Reset (RST) type */ + unsigned type = COAP_TYPE_RST; + if (code) { + if (coap_get_type(pkt) == COAP_TYPE_CON) { + type = COAP_TYPE_ACK; + } + else { + type = COAP_TYPE_NON; + } + } coap_build_hdr((coap_hdr_t *)rbuf, type, pkt->token, tkl, code, ntohs(pkt->hdr->id)); -- GitLab