diff --git a/man/coap_handler.txt.in b/man/coap_handler.txt.in index 2e355fcc7a..bda627eb50 100644 --- a/man/coap_handler.txt.in +++ b/man/coap_handler.txt.in @@ -141,6 +141,12 @@ this is an ACK or RST response to the request. In general, matching of Requests and Responses whould be done by generating unique Tokens for each Request and then matching up based on the Token in _received_ Response. +*NOTE:* _sent_ (if not NULL) may not contain all or any of the data used for the +initial request if block transfers are being used. For Block1 requests, the +complete data will be lost once the data has been successfully transmitted as +acknowledged by the first response. For Block2 responses, _sent_ gets re-used +to request the next Block2 and so data information is lost. + *NOTE:* If the returned value is COAP_RESPONSE_FAIL, then a CoAP RST packet will get sent to the server by libcoap. The returned value of COAP_RESPONSE_OK indicates that all is OK. diff --git a/src/coap_block.c b/src/coap_block.c index b2a511bda3..012a174c76 100644 --- a/src/coap_block.c +++ b/src/coap_block.c @@ -3316,6 +3316,15 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, coap_show_pdu(COAP_LOG_DEBUG, rcvd); } + if (sent) { + /* need to put back original token into sent */ + if (p->b.b1.app_token) + coap_update_token(sent, p->b.b1.app_token->length, + p->b.b1.app_token->s); + if (sent->lg_xmit) + coap_remove_option(sent, sent->lg_xmit->option); + sent->lg_xmit = NULL; + } LL_DELETE(session->lg_xmit, p); coap_block_delete_lg_xmit(session, p); return 0; @@ -3693,6 +3702,14 @@ coap_handle_response_get_block(coap_context_t *context, #endif /* ! COAP_Q_BLOCK_SUPPORT */ coap_log_debug("Client app version of updated PDU\n"); coap_show_pdu(COAP_LOG_DEBUG, rcvd); + + if (sent) { + /* need to put back original token into sent */ + if (p->app_token) + coap_update_token(sent, p->app_token->length, + p->app_token->s); + coap_remove_option(sent, p->block_option); + } goto call_app_handler; } #if COAP_Q_BLOCK_SUPPORT @@ -3730,6 +3747,13 @@ coap_handle_response_get_block(coap_context_t *context, coap_log_debug("Client app version of updated PDU\n"); coap_show_pdu(COAP_LOG_DEBUG, rcvd); } + if (sent) { + /* need to put back original token into sent */ + if (p->app_token) + coap_update_token(sent, p->app_token->length, + p->app_token->s); + coap_remove_option(sent, p->block_option); + } if (context->response_handler(session, sent, rcvd, rcvd->mid) == COAP_RESPONSE_FAIL) coap_send_rst(session, rcvd); @@ -3879,6 +3903,14 @@ coap_handle_response_get_block(coap_context_t *context, coap_log_debug("Client app version of updated PDU\n"); coap_show_pdu(COAP_LOG_DEBUG, rcvd); } + + if (sent) { + /* need to put back original token into sent */ + if (p->app_token) + coap_update_token(sent, p->app_token->length, + p->app_token->s); + coap_remove_option(sent, p->block_option); + } /* Expire this entry */ LL_DELETE(session->lg_crcv, p); coap_block_delete_lg_crcv(session, p);