Skip to content

Commit

Permalink
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 2d67eaf commit 1f27d10
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions sys/include/net/coap.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +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) /**< suppress CoAP response (RFC 7968) */
/** @} */

/**
Expand Down
1 change: 1 addition & 0 deletions sys/include/net/nanocoap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,7 @@ ssize_t coap_build_hdr(coap_hdr_t *hdr, unsigned type, uint8_t *token,
* @param[in] payload_len length of payload
*
* @returns size of reply packet on success
* @returns 0 if no response should be sent due to a No-Response option in the request
* @returns <0 on error
* @returns -ENOSPC if @p rbuf too small
*/
Expand Down
10 changes: 10 additions & 0 deletions sys/net/application_layer/nanocoap/nanocoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,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 1f27d10

Please sign in to comment.