Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/net/nanocoap: align request handling with spec #21163

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions sys/net/application_layer/nanocoap/nanocoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,16 +500,40 @@
coap_get_id(pkt));
}

switch (coap_get_type(pkt)) {
case COAP_TYPE_CON:
case COAP_TYPE_NON:
/* could be a request ==> proceed */
break;
default:
DEBUG_PUTS("coap_handle_req(): ignoring RST/ACK");
return -EBADMSG;
}

if (coap_get_code_class(pkt) != COAP_REQ) {
DEBUG("coap_handle_req(): not a request.\n");
DEBUG_PUTS("coap_handle_req(): not a request --> ignore");
return -EBADMSG;
}

if (pkt->hdr->code == 0) {
return coap_build_reply(pkt, COAP_CODE_EMPTY, resp_buf, resp_buf_len, 0);
if (coap_get_code_raw(pkt) == COAP_CODE_EMPTY) {
/* we are not able to process a CON/NON message with an empty code,
* so we reply with a RST, unless we got a multicast message */
if (!sock_udp_ep_is_multicast(coap_request_ctx_get_local_udp(ctx))) {
return coap_build_reply(pkt, COAP_CODE_EMPTY, resp_buf, resp_buf_len, 0);
}
}

ssize_t retval = coap_tree_handler(pkt, resp_buf, resp_buf_len, ctx,
coap_resources, coap_resources_numof);
if (retval < 0) {
/* handlers were not able to process this, so we reply with a RST,
* unless we got a multicast message */
if (!sock_udp_ep_is_multicast(coap_request_ctx_get_local_udp(ctx))) {
return coap_build_reply(pkt, COAP_CODE_EMPTY, resp_buf, resp_buf_len, 0);
}
}
return coap_tree_handler(pkt, resp_buf, resp_buf_len, ctx,
coap_resources, coap_resources_numof);

return retval;
}

ssize_t coap_subtree_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len,
Expand Down Expand Up @@ -914,7 +938,7 @@
return offset;
}

size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, const void *odata, size_t olen)

Check warning on line 941 in sys/net/application_layer/nanocoap/nanocoap.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
{
assert(lastonum <= onum);

Expand Down
Loading