Skip to content

Commit

Permalink
fixup! fixup! nanocoap: add support for no-response option
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Aug 29, 2022
1 parent 43da90c commit 2059803
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sys/include/net/coap.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extern "C" {
#define COAP_OPT_BLOCK1 (27)
#define COAP_OPT_PROXY_URI (35)
#define COAP_OPT_PROXY_SCHEME (39)
#define COAP_OPT_NO_RESPONSE (258)
#define COAP_OPT_NO_RESPONSE (258) /**< suppress CoAP response (RFC 7968) */
/** @} */

/**
Expand Down
20 changes: 10 additions & 10 deletions sys/net/application_layer/nanocoap/nanocoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,21 +498,11 @@ ssize_t coap_build_reply(coap_pkt_t *pkt, unsigned code,
{
unsigned tkl = coap_get_token_len(pkt);
unsigned len = sizeof(coap_hdr_t) + tkl;
uint32_t no_response;

if ((len + payload_len) > rlen) {
return -ENOSPC;
}

if (coap_opt_get_uint(pkt, COAP_OPT_NO_RESPONSE, &no_response) == 0) {
uint8_t mask = 1 << (code >> 5);

/* option contains bitmap of disinterest */
if (no_response & mask) {
return 0;
}
}

/* if code is COAP_CODE_EMPTY (zero), assume Reset (RST) type */
unsigned type = COAP_TYPE_RST;
if (code) {
Expand All @@ -524,6 +514,16 @@ ssize_t coap_build_reply(coap_pkt_t *pkt, unsigned code,
}
}

uint32_t no_response;
if (coap_opt_get_uint(pkt, COAP_OPT_NO_RESPONSE, &no_response) == 0) {
uint8_t mask = 1 << (code >> 5);

/* option contains bitmap of disinterest */
if ((type == COAP_TYPE_NON) && (no_response & mask)) {
return 0;
}
}

coap_build_hdr((coap_hdr_t *)rbuf, type, coap_get_token(pkt), tkl, code,
ntohs(pkt->hdr->id));
coap_hdr_set_type((coap_hdr_t *)rbuf, type);
Expand Down

0 comments on commit 2059803

Please sign in to comment.