diff --git a/sys/net/application_layer/nanocoap/nanocoap.c b/sys/net/application_layer/nanocoap/nanocoap.c index 262a01c1589d..5c79e95164e5 100644 --- a/sys/net/application_layer/nanocoap/nanocoap.c +++ b/sys/net/application_layer/nanocoap/nanocoap.c @@ -662,15 +662,15 @@ ssize_t coap_build_reply(coap_pkt_t *pkt, unsigned code, return -ENOSPC; } - /* 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; - } + unsigned type = COAP_TYPE_NON; + if (!code) { + /* if code is COAP_CODE_EMPTY (zero), assume Reset (RST) type. + * RST message have no token */ + type = COAP_TYPE_RST; + tkl = 0; + } + else if (coap_get_type(pkt) == COAP_TYPE_CON) { + type = COAP_TYPE_ACK; } uint32_t no_response;