Skip to content

Commit

Permalink
coap_session.c: Report COAP_NACK_ICMP_ISSUE for NON to NACK handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdeep1 committed Jul 22, 2023
1 parent 15473b0 commit e60205e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
11 changes: 7 additions & 4 deletions examples/coap-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,13 @@ static void
nack_handler(coap_session_t *session COAP_UNUSED,
const coap_pdu_t *sent,
const coap_nack_reason_t reason,
const coap_mid_t id COAP_UNUSED) {
coap_bin_const_t token = coap_pdu_get_token(sent);
if (!track_check_token(&token)) {
coap_log_err("nack_handler: Unexpected token\n");
const coap_mid_t mid COAP_UNUSED) {
if (sent) {
coap_bin_const_t token = coap_pdu_get_token(sent);

if (!track_check_token(&token)) {
coap_log_err("nack_handler: Unexpected token\n");
}
}

switch (reason) {
Expand Down
2 changes: 1 addition & 1 deletion examples/coap-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ static void
proxy_nack_handler(coap_session_t *session,
const coap_pdu_t *sent COAP_UNUSED,
const coap_nack_reason_t reason,
const coap_mid_t id COAP_UNUSED) {
const coap_mid_t mid COAP_UNUSED) {

switch (reason) {
case COAP_NACK_TOO_MANY_RETRIES:
Expand Down
16 changes: 16 additions & 0 deletions src/coap_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,17 +859,33 @@ coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reason) {

if (reason == COAP_NACK_ICMP_ISSUE) {
if (session->context->nack_handler) {
int sent_nack = 0;
coap_queue_t *q = session->context->sendqueue;
while (q) {
if (q->session == session) {
/* Take the first one */
coap_bin_const_t token = q->pdu->actual_token;

coap_check_update_token(session, q->pdu);
session->context->nack_handler(session, q->pdu, reason, q->id);
coap_update_token(q->pdu, token.length, token.s);
sent_nack = 1;
break;
}
q = q->next;
}
#if COAP_CLIENT_SUPPORT
if (!sent_nack && session->lg_crcv) {
/* Take the first one */
session->context->nack_handler(session, &session->lg_crcv->pdu, reason,
session->lg_crcv->pdu.mid);
sent_nack = 1;
}
#endif /* COAP_CLIENT_SUPPORT */
if (!sent_nack) {
/* Unable to determine which request ICMP issue was for */
session->context->nack_handler(session, NULL, reason, 0);
}
}
coap_log_debug("***%s: session issue (%s)\n",
coap_session_str(session), coap_nack_name(reason));
Expand Down

0 comments on commit e60205e

Please sign in to comment.