1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00
18773: nanocoap_sock: fix handling empty ACKs with separate response r=maribu a=benpicco



Co-authored-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
Co-authored-by: Benjamin Valentin <benjamin.valentin@bht-berlin.de>
This commit is contained in:
bors[bot] 2023-01-06 01:07:57 +00:00 committed by GitHub
commit 6cf2116ae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -252,6 +252,14 @@ extern "C" {
#define CONFIG_COAP_RANDOM_FACTOR_1000 (1500)
#endif
/**
* @brief Timeout in milliseconds for a separate (deferred) response
* sent after an empty ACK.
*/
#ifndef CONFIG_COAP_SEPARATE_RESPONSE_TIMEOUT_MS
#define CONFIG_COAP_SEPARATE_RESPONSE_TIMEOUT_MS (10 * MS_PER_SEC)
#endif
/** @brief Maximum number of retransmissions for a confirmable request */
#ifndef CONFIG_COAP_MAX_RETRANSMIT
#define CONFIG_COAP_MAX_RETRANSMIT (4)

View File

@ -74,7 +74,7 @@ static int _send_ack(nanocoap_sock_t *sock, coap_pkt_t *pkt)
unsigned tkl = coap_get_token_len(pkt);
coap_build_hdr(&ack, COAP_TYPE_ACK, coap_get_token(pkt), tkl,
COAP_CODE_VALID, ntohs(pkt->hdr->id));
COAP_CODE_EMPTY, ntohs(pkt->hdr->id));
return sock_udp_send(sock, &ack, sizeof(ack), NULL);
}
@ -224,8 +224,17 @@ ssize_t nanocoap_sock_request_cb(nanocoap_sock_t *sock, coap_pkt_t *pkt,
case COAP_TYPE_CON:
_send_ack(sock, pkt);
/* fall-through */
case COAP_TYPE_NON:
case COAP_TYPE_ACK:
if (cb && coap_get_code(pkt) == COAP_CODE_EMPTY) {
/* empty ACK, wait for separate response */
state = STATE_RESPONSE_RCVD;
deadline = _deadline_from_interval(CONFIG_COAP_SEPARATE_RESPONSE_TIMEOUT_MS
* US_PER_MS);
DEBUG("nanocoap: wait for separate response\n");
continue;
}
/* fall-through */
case COAP_TYPE_NON:
/* call user callback */
if (cb) {
res = cb(arg, pkt);