diff --git a/src/coap_block.c b/src/coap_block.c index 0e13ba146c..6ff863e220 100644 --- a/src/coap_block.c +++ b/src/coap_block.c @@ -1273,7 +1273,7 @@ coap_add_data_large_response_lkd(coap_resource_t *resource, int coap_block_check_lg_xmit_timeouts(coap_session_t *session, coap_tick_t now, coap_tick_t *tim_rem) { - coap_lg_xmit_t *p; + coap_lg_xmit_t *lg_xmit; coap_lg_xmit_t *q; #if COAP_Q_BLOCK_SUPPORT coap_tick_t idle_timeout = 4 * COAP_NON_TIMEOUT_TICKS(session); @@ -1285,29 +1285,29 @@ coap_block_check_lg_xmit_timeouts(coap_session_t *session, coap_tick_t now, *tim_rem = -1; - LL_FOREACH_SAFE(session->lg_xmit, p, q) { - if (p->last_all_sent) { - if (p->last_all_sent + idle_timeout <= now) { + LL_FOREACH_SAFE(session->lg_xmit, lg_xmit, q) { + if (lg_xmit->last_all_sent) { + if (lg_xmit->last_all_sent + idle_timeout <= now) { /* Expire this entry */ - LL_DELETE(session->lg_xmit, p); - coap_block_delete_lg_xmit(session, p); + LL_DELETE(session->lg_xmit, lg_xmit); + coap_block_delete_lg_xmit(session, lg_xmit); } else { /* Delay until the lg_xmit needs to expire */ - if (*tim_rem > p->last_all_sent + idle_timeout - now) { - *tim_rem = p->last_all_sent + idle_timeout - now; + if (*tim_rem > lg_xmit->last_all_sent + idle_timeout - now) { + *tim_rem = lg_xmit->last_all_sent + idle_timeout - now; ret = 1; } } - } else if (p->last_sent) { - if (p->last_sent + partial_timeout <= now) { + } else if (lg_xmit->last_sent) { + if (lg_xmit->last_sent + partial_timeout <= now) { /* Expire this entry */ - LL_DELETE(session->lg_xmit, p); - coap_block_delete_lg_xmit(session, p); + LL_DELETE(session->lg_xmit, lg_xmit); + coap_block_delete_lg_xmit(session, lg_xmit); coap_handle_event_lkd(session->context, COAP_EVENT_XMIT_BLOCK_FAIL, session); } else { /* Delay until the lg_xmit needs to expire */ - if (*tim_rem > p->last_sent + partial_timeout - now) { - *tim_rem = p->last_sent + partial_timeout - now; + if (*tim_rem > lg_xmit->last_sent + partial_timeout - now) { + *tim_rem = lg_xmit->last_sent + partial_timeout - now; ret = 1; } } @@ -1319,21 +1319,21 @@ coap_block_check_lg_xmit_timeouts(coap_session_t *session, coap_tick_t now, #if COAP_CLIENT_SUPPORT #if COAP_Q_BLOCK_SUPPORT static coap_pdu_t * -coap_build_missing_pdu(coap_session_t *session, coap_lg_crcv_t *p) { +coap_build_missing_pdu(coap_session_t *session, coap_lg_crcv_t *lg_crcv) { coap_pdu_t *pdu; coap_opt_filter_t drop_options; - uint64_t token = STATE_TOKEN_FULL(p->state_token, ++p->retry_counter); + uint64_t token = STATE_TOKEN_FULL(lg_crcv->state_token, ++lg_crcv->retry_counter); uint8_t buf[8]; size_t len = coap_encode_var_safe8(buf, sizeof(token), token); memset(&drop_options, 0, sizeof(coap_opt_filter_t)); coap_option_filter_set(&drop_options, COAP_OPTION_Q_BLOCK2); coap_option_filter_set(&drop_options, COAP_OPTION_OBSERVE); - pdu = coap_pdu_duplicate_lkd(&p->pdu, session, len, buf, + pdu = coap_pdu_duplicate_lkd(&lg_crcv->pdu, session, len, buf, &drop_options); if (!pdu) return NULL; - pdu->type = p->last_type; + pdu->type = lg_crcv->last_type; return pdu; } @@ -1442,7 +1442,7 @@ coap_request_missing_q_block2(coap_session_t *session, coap_lg_crcv_t *lg_crcv) int coap_block_check_lg_crcv_timeouts(coap_session_t *session, coap_tick_t now, coap_tick_t *tim_rem) { - coap_lg_crcv_t *p; + coap_lg_crcv_t *lg_crcv; coap_lg_crcv_t *q; coap_tick_t partial_timeout; #if COAP_Q_BLOCK_SUPPORT @@ -1459,29 +1459,29 @@ coap_block_check_lg_crcv_timeouts(coap_session_t *session, coap_tick_t now, #endif /* COAP_Q_BLOCK_SUPPORT */ partial_timeout = COAP_MAX_TRANSMIT_WAIT_TICKS(session); - LL_FOREACH_SAFE(session->lg_crcv, p, q) { - if (COAP_PROTO_RELIABLE(session->proto) || p->last_type != COAP_MESSAGE_NON) + LL_FOREACH_SAFE(session->lg_crcv, lg_crcv, q) { + if (COAP_PROTO_RELIABLE(session->proto) || lg_crcv->last_type != COAP_MESSAGE_NON) goto check_expire; #if COAP_Q_BLOCK_SUPPORT - if (p->block_option == COAP_OPTION_Q_BLOCK2 && p->rec_blocks.used) { + if (lg_crcv->block_option == COAP_OPTION_Q_BLOCK2 && lg_crcv->rec_blocks.used) { size_t scaled_timeout = receive_timeout * - ((size_t)1 << p->rec_blocks.retry); + ((size_t)1 << lg_crcv->rec_blocks.retry); - if (p->rec_blocks.retry >= COAP_NON_MAX_RETRANSMIT(session)) { + if (lg_crcv->rec_blocks.retry >= COAP_NON_MAX_RETRANSMIT(session)) { /* Done NON_MAX_RETRANSMIT retries */ - coap_update_token(&p->pdu, p->app_token->length, p->app_token->s); + coap_update_token(&lg_crcv->pdu, lg_crcv->app_token->length, lg_crcv->app_token->s); coap_lock_callback(session->context, - session->context->nack_handler(session, &p->pdu, + session->context->nack_handler(session, &lg_crcv->pdu, COAP_NACK_TOO_MANY_RETRIES, - p->pdu.mid)); + lg_crcv->pdu.mid)); goto expire; } - if (p->rec_blocks.last_seen + scaled_timeout <= now) { - coap_request_missing_q_block2(session, p); + if (lg_crcv->rec_blocks.last_seen + scaled_timeout <= now) { + coap_request_missing_q_block2(session, lg_crcv); } else { - if (*tim_rem > p->rec_blocks.last_seen + scaled_timeout - now) { - *tim_rem = p->rec_blocks.last_seen + scaled_timeout - now; + if (*tim_rem > lg_crcv->rec_blocks.last_seen + scaled_timeout - now) { + *tim_rem = lg_crcv->rec_blocks.last_seen + scaled_timeout - now; ret = 1; } } @@ -1489,18 +1489,18 @@ coap_block_check_lg_crcv_timeouts(coap_session_t *session, coap_tick_t now, #endif /* COAP_Q_BLOCK_SUPPORT */ /* Used for Block2 and Q-Block2 */ check_expire: - if (!p->observe_set && p->last_used && - p->last_used + partial_timeout <= now) { + if (!lg_crcv->observe_set && lg_crcv->last_used && + lg_crcv->last_used + partial_timeout <= now) { #if COAP_Q_BLOCK_SUPPORT expire: #endif /* COAP_Q_BLOCK_SUPPORT */ /* Expire this entry */ - LL_DELETE(session->lg_crcv, p); - coap_block_delete_lg_crcv(session, p); - } else if (!p->observe_set && p->last_used) { + LL_DELETE(session->lg_crcv, lg_crcv); + coap_block_delete_lg_crcv(session, lg_crcv); + } else if (!lg_crcv->observe_set && lg_crcv->last_used) { /* Delay until the lg_crcv needs to expire */ - if (*tim_rem > p->last_used + partial_timeout - now) { - *tim_rem = p->last_used + partial_timeout - now; + if (*tim_rem > lg_crcv->last_used + partial_timeout - now) { + *tim_rem = lg_crcv->last_used + partial_timeout - now; ret = 1; } } @@ -1512,7 +1512,7 @@ coap_block_check_lg_crcv_timeouts(coap_session_t *session, coap_tick_t now, #if COAP_SERVER_SUPPORT #if COAP_Q_BLOCK_SUPPORT static coap_pdu_t * -pdu_408_build(coap_session_t *session, coap_lg_srcv_t *p) { +pdu_408_build(coap_session_t *session, coap_lg_srcv_t *lg_srcv) { coap_pdu_t *pdu; uint8_t buf[4]; @@ -1522,8 +1522,8 @@ pdu_408_build(coap_session_t *session, coap_lg_srcv_t *p) { coap_session_max_pdu_size_lkd(session)); if (!pdu) return NULL; - if (p->last_token) - coap_add_token(pdu, p->last_token->length, p->last_token->s); + if (lg_srcv->last_token) + coap_add_token(pdu, lg_srcv->last_token->length, lg_srcv->last_token->s); coap_add_option_internal(pdu, COAP_OPTION_CONTENT_TYPE, coap_encode_var_safe(buf, sizeof(buf), COAP_MEDIATYPE_APPLICATION_MB_CBOR_SEQ), @@ -1647,7 +1647,7 @@ check_any_blocks_next_payload_set(coap_session_t *session, int coap_block_check_lg_srcv_timeouts(coap_session_t *session, coap_tick_t now, coap_tick_t *tim_rem) { - coap_lg_srcv_t *p; + coap_lg_srcv_t *lg_srcv; coap_lg_srcv_t *q; coap_tick_t partial_timeout; #if COAP_Q_BLOCK_SUPPORT @@ -1664,38 +1664,38 @@ coap_block_check_lg_srcv_timeouts(coap_session_t *session, coap_tick_t now, #endif /* COAP_Q_BLOCK_SUPPORT */ partial_timeout = COAP_MAX_TRANSMIT_WAIT_TICKS(session); - LL_FOREACH_SAFE(session->lg_srcv, p, q) { - if (COAP_PROTO_RELIABLE(session->proto) || p->last_type != COAP_MESSAGE_NON) + LL_FOREACH_SAFE(session->lg_srcv, lg_srcv, q) { + if (COAP_PROTO_RELIABLE(session->proto) || lg_srcv->last_type != COAP_MESSAGE_NON) goto check_expire; #if COAP_Q_BLOCK_SUPPORT - if (p->block_option == COAP_OPTION_Q_BLOCK1 && p->rec_blocks.used) { + if (lg_srcv->block_option == COAP_OPTION_Q_BLOCK1 && lg_srcv->rec_blocks.used) { size_t scaled_timeout = receive_timeout * - ((size_t)1 << p->rec_blocks.retry); + ((size_t)1 << lg_srcv->rec_blocks.retry); - if (p->rec_blocks.retry >= COAP_NON_MAX_RETRANSMIT(session)) { + if (lg_srcv->rec_blocks.retry >= COAP_NON_MAX_RETRANSMIT(session)) { /* Done NON_MAX_RETRANSMIT retries */ goto expire; } - if (p->rec_blocks.last_seen + scaled_timeout <= now) { + if (lg_srcv->rec_blocks.last_seen + scaled_timeout <= now) { uint32_t i; int block = -1; /* Last one seen */ - size_t block_size = (size_t)1 << (p->szx + 4); - size_t final_block = (p->total_len + block_size - 1)/block_size - 1; + size_t block_size = (size_t)1 << (lg_srcv->szx + 4); + size_t final_block = (lg_srcv->total_len + block_size - 1)/block_size - 1; size_t cur_payload; size_t last_payload_block; coap_pdu_t *pdu = NULL; size_t no_blocks = 0; /* Need to count the number of missing blocks */ - for (i = 0; i < p->rec_blocks.used; i++) { - if (block < (int)p->rec_blocks.range[i].begin && - p->rec_blocks.range[i].begin != 0) { + for (i = 0; i < lg_srcv->rec_blocks.used; i++) { + if (block < (int)lg_srcv->rec_blocks.range[i].begin && + lg_srcv->rec_blocks.range[i].begin != 0) { block++; - no_blocks += p->rec_blocks.range[i].begin - block; + no_blocks += lg_srcv->rec_blocks.range[i].begin - block; } - if (block < (int)p->rec_blocks.range[i].end) { - block = p->rec_blocks.range[i].end; + if (block < (int)lg_srcv->rec_blocks.range[i].end) { + block = lg_srcv->rec_blocks.range[i].end; } } if (no_blocks == 0 && block == (int)final_block) @@ -1710,7 +1710,7 @@ coap_block_check_lg_srcv_timeouts(coap_session_t *session, coap_tick_t now, no_blocks += final_block - block; if (no_blocks == 0) { /* Add in the blocks out of the next payload */ - final_block = (p->total_len + block_size - 1)/block_size - 1; + final_block = (lg_srcv->total_len + block_size - 1)/block_size - 1; last_payload_block += COAP_MAX_PAYLOADS(session); if (final_block > last_payload_block) { final_block = last_payload_block; @@ -1718,30 +1718,30 @@ coap_block_check_lg_srcv_timeouts(coap_session_t *session, coap_tick_t now, } /* Ask for the missing blocks */ block = -1; - for (i = 0; i < p->rec_blocks.used; i++) { - if (block < (int)p->rec_blocks.range[i].begin && - p->rec_blocks.range[i].begin != 0) { + for (i = 0; i < lg_srcv->rec_blocks.used; i++) { + if (block < (int)lg_srcv->rec_blocks.range[i].begin && + lg_srcv->rec_blocks.range[i].begin != 0) { /* Report on missing blocks */ if (pdu == NULL) { - pdu = pdu_408_build(session, p); + pdu = pdu_408_build(session, lg_srcv); if (!pdu) continue; } block++; - for (; block < (int)p->rec_blocks.range[i].begin; block++) { + for (; block < (int)lg_srcv->rec_blocks.range[i].begin; block++) { if (!add_408_block(pdu, block)) { break; } } } - if (block < (int)p->rec_blocks.range[i].end) { - block = p->rec_blocks.range[i].end; + if (block < (int)lg_srcv->rec_blocks.range[i].end) { + block = lg_srcv->rec_blocks.range[i].end; } } block++; for (; block <= (int)final_block; block++) { if (pdu == NULL) { - pdu = pdu_408_build(session, p); + pdu = pdu_408_build(session, lg_srcv); if (!pdu) continue; } @@ -1751,25 +1751,25 @@ coap_block_check_lg_srcv_timeouts(coap_session_t *session, coap_tick_t now, } if (pdu) coap_send_internal(session, pdu); - p->rec_blocks.retry++; - coap_ticks(&p->rec_blocks.last_seen); + lg_srcv->rec_blocks.retry++; + coap_ticks(&lg_srcv->rec_blocks.last_seen); } - if (*tim_rem > p->rec_blocks.last_seen + scaled_timeout - now) { - *tim_rem = p->rec_blocks.last_seen + scaled_timeout - now; + if (*tim_rem > lg_srcv->rec_blocks.last_seen + scaled_timeout - now) { + *tim_rem = lg_srcv->rec_blocks.last_seen + scaled_timeout - now; ret = 1; } } #endif /* COAP_Q_BLOCK_SUPPORT */ /* Used for Block1 and Q-Block1 */ check_expire: - if (p->no_more_seen) + if (lg_srcv->no_more_seen) partial_timeout = 10 * COAP_TICKS_PER_SECOND; - if (p->last_used && p->last_used + partial_timeout <= now) { + if (lg_srcv->last_used && lg_srcv->last_used + partial_timeout <= now) { #if COAP_Q_BLOCK_SUPPORT expire: #endif /* COAP_Q_BLOCK_SUPPORT */ /* Expire this entry */ - if (p->no_more_seen && p->block_option == COAP_OPTION_BLOCK1) { + if (lg_srcv->no_more_seen && lg_srcv->block_option == COAP_OPTION_BLOCK1) { /* * Need to send a separate 4.08 to indicate missing blocks * Using NON is permissable as per @@ -1782,19 +1782,19 @@ coap_block_check_lg_srcv_timeouts(coap_session_t *session, coap_tick_t now, coap_new_message_id_lkd(session), coap_session_max_pdu_size_lkd(session)); if (pdu) { - if (p->last_token) - coap_add_token(pdu, p->last_token->length, p->last_token->s); + if (lg_srcv->last_token) + coap_add_token(pdu, lg_srcv->last_token->length, lg_srcv->last_token->s); coap_add_data(pdu, sizeof("Missing interim block")-1, (const uint8_t *)"Missing interim block"); coap_send_internal(session, pdu); } } - LL_DELETE(session->lg_srcv, p); - coap_block_delete_lg_srcv(session, p); - } else if (p->last_used) { + LL_DELETE(session->lg_srcv, lg_srcv); + coap_block_delete_lg_srcv(session, lg_srcv); + } else if (lg_srcv->last_used) { /* Delay until the lg_srcv needs to expire */ - if (*tim_rem > p->last_used + partial_timeout - now) { - *tim_rem = p->last_used + partial_timeout - now; + if (*tim_rem > lg_srcv->last_used + partial_timeout - now) { + *tim_rem = lg_srcv->last_used + partial_timeout - now; ret = 1; } } @@ -2409,7 +2409,7 @@ coap_handle_request_send_block(coap_session_t *session, coap_pdu_t *response, coap_resource_t *resource, coap_string_t *query) { - coap_lg_xmit_t *p = NULL; + coap_lg_xmit_t *lg_xmit = NULL; coap_block_b_t block; coap_block_b_t alt_block; uint16_t block_opt = 0; @@ -2449,8 +2449,8 @@ coap_handle_request_send_block(coap_session_t *session, /* Get a fresh copy of the data */ return 0; } - p = coap_find_lg_xmit_response(session, pdu, resource, query); - if (p == NULL) + lg_xmit = coap_find_lg_xmit_response(session, pdu, resource, query); + if (lg_xmit == NULL) return 0; #if COAP_Q_BLOCK_SUPPORT @@ -2468,20 +2468,20 @@ coap_handle_request_send_block(coap_session_t *session, if (etag_opt) { uint64_t etag = coap_decode_var_bytes8(coap_opt_value(etag_opt), coap_opt_length(etag_opt)); - if (etag != p->b.b2.etag) { + if (etag != lg_xmit->b.b2.etag) { /* Not a match - pass up to a higher level */ return 0; } out_pdu->code = COAP_RESPONSE_CODE(203); - coap_ticks(&p->last_sent); + coap_ticks(&lg_xmit->last_sent); goto skip_app_handler; } else { - out_pdu->code = p->pdu.code; + out_pdu->code = lg_xmit->pdu.code; } - coap_ticks(&p->last_obs); - p->last_all_sent = 0; + coap_ticks(&lg_xmit->last_obs); + lg_xmit->last_all_sent = 0; - chunk = (size_t)1 << (p->blk_size + 4); + chunk = (size_t)1 << (lg_xmit->blk_size + 4); if (block_opt) { if (block.bert) { coap_log_debug("found Block option, block is BERT, block nr. %u, M %d\n", @@ -2490,31 +2490,31 @@ coap_handle_request_send_block(coap_session_t *session, coap_log_debug("found Block option, block size is %u, block nr. %u, M %d\n", 1 << (block.szx + 4), block.num, block.m); } - if (block.bert == 0 && block.szx != p->blk_size) { + if (block.bert == 0 && block.szx != lg_xmit->blk_size) { if (block.num == 0) { - if ((p->offset + chunk) % ((size_t)1 << (block.szx + 4)) == 0) { + if ((lg_xmit->offset + chunk) % ((size_t)1 << (block.szx + 4)) == 0) { /* * Recompute the block number of the previous packet given * the new block size */ - block.num = (uint32_t)(((p->offset + chunk) >> (block.szx + 4)) - 1); - p->blk_size = block.szx; - chunk = (size_t)1 << (p->blk_size + 4); - p->offset = block.num * chunk; + block.num = (uint32_t)(((lg_xmit->offset + chunk) >> (block.szx + 4)) - 1); + lg_xmit->blk_size = block.szx; + chunk = (size_t)1 << (lg_xmit->blk_size + 4); + lg_xmit->offset = block.num * chunk; coap_log_debug("new Block size is %u, block number %u completed\n", 1 << (block.szx + 4), block.num); } else { coap_log_debug("ignoring request to increase Block size, " "next block is not aligned on requested block size " "boundary. (%zu x %u mod %u = %zu (which is not 0)\n", - p->offset/chunk + 1, (1 << (p->blk_size + 4)), + lg_xmit->offset/chunk + 1, (1 << (lg_xmit->blk_size + 4)), (1 << (block.szx + 4)), - (p->offset + chunk) % ((size_t)1 << (block.szx + 4))); + (lg_xmit->offset + chunk) % ((size_t)1 << (block.szx + 4))); } } else { coap_log_debug("ignoring request to change Block size from %u to %u\n", - (1 << (p->blk_size + 4)), (1 << (block.szx + 4))); - block.szx = block.aszx = p->blk_size; + (1 << (lg_xmit->blk_size + 4)), (1 << (block.szx + 4))); + block.szx = block.aszx = lg_xmit->blk_size; } } } @@ -2526,12 +2526,12 @@ coap_handle_request_send_block(coap_session_t *session, */ request_cnt = 0; #if COAP_Q_BLOCK_SUPPORT - max_block = (p->length + chunk - 1)/chunk; + max_block = (lg_xmit->length + chunk - 1)/chunk; #endif /* COAP_Q_BLOCK_SUPPORT */ coap_option_iterator_init(pdu, &opt_b_iter, COAP_OPT_ALL); while ((option = coap_option_next(&opt_b_iter))) { uint32_t num; - if (opt_b_iter.number != p->option) + if (opt_b_iter.number != lg_xmit->option) continue; num = coap_opt_block_num(option); if (num > 0xFFFFF) /* 20 bits max for num */ @@ -2544,7 +2544,7 @@ coap_handle_request_send_block(coap_session_t *session, goto skip_app_handler; } #if COAP_Q_BLOCK_SUPPORT - if (COAP_OPT_BLOCK_MORE(option) && p->option == COAP_OPTION_Q_BLOCK2) { + if (COAP_OPT_BLOCK_MORE(option) && lg_xmit->option == COAP_OPTION_Q_BLOCK2) { if ((num % COAP_MAX_PAYLOADS(session)) == 0) { if (num == 0) { /* This is a repeat request for everything - hmm */ @@ -2555,7 +2555,7 @@ coap_handle_request_send_block(coap_session_t *session, num + i < max_block; i++) { add_block_send(num + i, 1, out_blocks, &request_cnt, COAP_MAX_PAYLOADS(session)); - p->last_block = num + i; + lg_xmit->last_block = num + i; } } else { /* Requesting remaining payloads in this MAX_PAYLOADS */ @@ -2576,8 +2576,8 @@ coap_handle_request_send_block(coap_session_t *session, } if (request_cnt == 0) { /* Block2 or Q-Block2 not found - give them the first block */ - block.szx = p->blk_size; - p->offset = 0; + block.szx = lg_xmit->blk_size; + lg_xmit->offset = 0; out_blocks[0].num = 0; out_blocks[0].is_continue = 0; request_cnt = 1; @@ -2587,7 +2587,7 @@ coap_handle_request_send_block(coap_session_t *session, uint8_t buf[8]; block.num = out_blocks[i].num; - p->offset = block.num * chunk; + lg_xmit->offset = block.num * chunk; if (i + 1 < request_cnt) { /* Need to set up a copy of the pdu to send */ @@ -2597,10 +2597,10 @@ coap_handle_request_send_block(coap_session_t *session, if (block.num != 0) coap_option_filter_set(&drop_options, COAP_OPTION_OBSERVE); if (out_blocks[i].is_continue) { - out_pdu = coap_pdu_duplicate_lkd(&p->pdu, session, p->pdu.actual_token.length, - p->pdu.actual_token.s, &drop_options); + out_pdu = coap_pdu_duplicate_lkd(&lg_xmit->pdu, session, lg_xmit->pdu.actual_token.length, + lg_xmit->pdu.actual_token.s, &drop_options); } else { - out_pdu = coap_pdu_duplicate_lkd(&p->pdu, session, pdu->actual_token.length, + out_pdu = coap_pdu_duplicate_lkd(&lg_xmit->pdu, session, pdu->actual_token.length, pdu->actual_token.s, &drop_options); } if (!out_pdu) { @@ -2608,14 +2608,14 @@ coap_handle_request_send_block(coap_session_t *session, } } else { if (out_blocks[i].is_continue) - coap_update_token(response, p->pdu.actual_token.length, - p->pdu.actual_token.s); + coap_update_token(response, lg_xmit->pdu.actual_token.length, + lg_xmit->pdu.actual_token.s); /* * Copy the options across and then fix the block option * * Need to drop Observe option if Block2 and block.num != 0 */ - coap_option_iterator_init(&p->pdu, &opt_iter, COAP_OPT_ALL); + coap_option_iterator_init(&lg_xmit->pdu, &opt_iter, COAP_OPT_ALL); while ((option = coap_option_next(&opt_iter))) { if (opt_iter.number == COAP_OPTION_OBSERVE && block.num != 0) continue; @@ -2631,12 +2631,12 @@ coap_handle_request_send_block(coap_session_t *session, out_pdu->type = COAP_MESSAGE_NON; if (block.bert) { size_t token_options = pdu->data ? (size_t)(pdu->data - pdu->token) : pdu->used_size; - block.m = (p->length - p->offset) > + block.m = (lg_xmit->length - lg_xmit->offset) > ((out_pdu->max_size - token_options) /1024) * 1024; } else { - block.m = (p->offset + chunk) < p->length; + block.m = (lg_xmit->offset + chunk) < lg_xmit->length; } - if (!coap_update_option(out_pdu, p->option, + if (!coap_update_option(out_pdu, lg_xmit->option, coap_encode_var_safe(buf, sizeof(buf), (block.num << 4) | @@ -2645,26 +2645,26 @@ coap_handle_request_send_block(coap_session_t *session, buf)) { goto internal_issue; } - if (!(p->offset + chunk < p->length)) { + if (!(lg_xmit->offset + chunk < lg_xmit->length)) { /* Last block - keep in cache for 4 * ACK_TIMOUT */ - coap_ticks(&p->last_all_sent); + coap_ticks(&lg_xmit->last_all_sent); } - if (p->b.b2.maxage_expire) { + if (lg_xmit->b.b2.maxage_expire) { coap_tick_t now; coap_time_t rem; - if (!(p->offset + chunk < p->length)) { + if (!(lg_xmit->offset + chunk < lg_xmit->length)) { /* Last block - keep in cache for 4 * ACK_TIMOUT */ - coap_ticks(&p->last_all_sent); + coap_ticks(&lg_xmit->last_all_sent); } coap_ticks(&now); rem = coap_ticks_to_rt(now); - if (p->b.b2.maxage_expire > rem) { - rem = p->b.b2.maxage_expire - rem; + if (lg_xmit->b.b2.maxage_expire > rem) { + rem = lg_xmit->b.b2.maxage_expire - rem; } else { rem = 0; /* Entry needs to be expired */ - coap_ticks(&p->last_all_sent); + coap_ticks(&lg_xmit->last_all_sent); } if (!coap_update_option(out_pdu, COAP_OPTION_MAXAGE, coap_encode_var_safe8(buf, @@ -2676,17 +2676,17 @@ coap_handle_request_send_block(coap_session_t *session, } if (!etag_opt && !coap_add_block_b_data(out_pdu, - p->length, - p->data, + lg_xmit->length, + lg_xmit->data, &block)) { goto internal_issue; } if (i + 1 < request_cnt) { - coap_ticks(&p->last_sent); + coap_ticks(&lg_xmit->last_sent); coap_send_internal(session, out_pdu); } } - coap_ticks(&p->last_payload); + coap_ticks(&lg_xmit->last_payload); goto skip_app_handler; #if COAP_Q_BLOCK_SUPPORT call_app_handler: @@ -2700,8 +2700,8 @@ coap_handle_request_send_block(coap_session_t *session, coap_add_data(response, strlen(error_phrase), (const uint8_t *)error_phrase); /* Keep in cache for 4 * ACK_TIMOUT incase of retry */ - if (p) - coap_ticks(&p->last_all_sent); + if (lg_xmit) + coap_ticks(&lg_xmit->last_all_sent); skip_app_handler: coap_free_type(COAP_STRING, out_blocks); @@ -2789,7 +2789,7 @@ coap_handle_request_put_block(coap_context_t *context, coap_block_b_t block; coap_opt_iterator_t opt_iter; uint16_t block_option = 0; - coap_lg_srcv_t *p; + coap_lg_srcv_t *lg_srcv; coap_opt_t *size_opt; coap_opt_t *fmt_opt; uint16_t fmt; @@ -2892,81 +2892,81 @@ coap_handle_request_put_block(coap_context_t *context, /* * locate the lg_srcv */ - LL_FOREACH(session->lg_srcv, p) { - if (rtag_opt || p->rtag_set == 1) { - if (!(rtag_opt && p->rtag_set == 1)) + LL_FOREACH(session->lg_srcv, lg_srcv) { + if (rtag_opt || lg_srcv->rtag_set == 1) { + if (!(rtag_opt && lg_srcv->rtag_set == 1)) continue; - if (p->rtag_length != rtag_length || - memcmp(p->rtag, rtag, rtag_length) != 0) + if (lg_srcv->rtag_length != rtag_length || + memcmp(lg_srcv->rtag, rtag, rtag_length) != 0) continue; } - if (resource == p->resource) { + if (resource == lg_srcv->resource) { break; } - if ((p->resource == context->unknown_resource || + if ((lg_srcv->resource == context->unknown_resource || resource == context->proxy_uri_resource) && - coap_string_equal(uri_path, p->uri_path)) + coap_string_equal(uri_path, lg_srcv->uri_path)) break; } - if (!p && block.num != 0 && session->block_mode & COAP_BLOCK_NOT_RANDOM_BLOCK1) { + if (!lg_srcv && block.num != 0 && session->block_mode & COAP_BLOCK_NOT_RANDOM_BLOCK1) { coap_add_data(response, sizeof("Missing block 0")-1, (const uint8_t *)"Missing block 0"); response->code = COAP_RESPONSE_CODE(408); goto skip_app_handler; } - if (!p) { + if (!lg_srcv) { /* Allocate lg_srcv to use for tracking */ - p = coap_malloc_type(COAP_LG_SRCV, sizeof(coap_lg_srcv_t)); - if (p == NULL) { + lg_srcv = coap_malloc_type(COAP_LG_SRCV, sizeof(coap_lg_srcv_t)); + if (lg_srcv == NULL) { coap_add_data(response, sizeof("Memory issue")-1, (const uint8_t *)"Memory issue"); response->code = COAP_RESPONSE_CODE(500); goto skip_app_handler; } coap_log_debug("** %s: lg_srcv %p initialized\n", - coap_session_str(session), (void *)p); - memset(p, 0, sizeof(coap_lg_srcv_t)); - coap_ticks(&p->last_used); - p->resource = resource; + coap_session_str(session), (void *)lg_srcv); + memset(lg_srcv, 0, sizeof(coap_lg_srcv_t)); + coap_ticks(&lg_srcv->last_used); + lg_srcv->resource = resource; if (resource == context->unknown_resource || resource == context->proxy_uri_resource) - p->uri_path = coap_new_str_const(uri_path->s, uri_path->length); - p->content_format = fmt; - p->total_len = total; + lg_srcv->uri_path = coap_new_str_const(uri_path->s, uri_path->length); + lg_srcv->content_format = fmt; + lg_srcv->total_len = total; max_block_szx = COAP_BLOCK_MAX_SIZE_GET(session->block_mode); if (!block.bert && block.num == 0 && max_block_szx != 0 && max_block_szx < block.szx) { - p->szx = max_block_szx; + lg_srcv->szx = max_block_szx; } else { - p->szx = block.szx; + lg_srcv->szx = block.szx; } - p->block_option = block_option; + lg_srcv->block_option = block_option; if (observe) { - p->observe_length = min(coap_opt_length(observe), 3); - memcpy(p->observe, coap_opt_value(observe), p->observe_length); - p->observe_set = 1; + lg_srcv->observe_length = min(coap_opt_length(observe), 3); + memcpy(lg_srcv->observe, coap_opt_value(observe), lg_srcv->observe_length); + lg_srcv->observe_set = 1; } if (rtag_opt) { - p->rtag_length = coap_opt_length(rtag_opt); - memcpy(p->rtag, coap_opt_value(rtag_opt), p->rtag_length); - p->rtag_set = 1; + lg_srcv->rtag_length = coap_opt_length(rtag_opt); + memcpy(lg_srcv->rtag, coap_opt_value(rtag_opt), lg_srcv->rtag_length); + lg_srcv->rtag_set = 1; } - p->body_data = NULL; - LL_PREPEND(session->lg_srcv, p); + lg_srcv->body_data = NULL; + LL_PREPEND(session->lg_srcv, lg_srcv); } if (block_option == COAP_OPTION_BLOCK1 && session->block_mode & COAP_BLOCK_NOT_RANDOM_BLOCK1 && - !check_if_next_block(&p->rec_blocks, block.num)) { + !check_if_next_block(&lg_srcv->rec_blocks, block.num)) { coap_add_data(response, sizeof("Missing interim block")-1, (const uint8_t *)"Missing interim block"); response->code = COAP_RESPONSE_CODE(408); goto skip_app_handler; } - if (fmt != p->content_format) { + if (fmt != lg_srcv->content_format) { coap_add_data(response, sizeof("Content-Format mismatch")-1, (const uint8_t *)"Content-Format mismatch"); response->code = COAP_RESPONSE_CODE(408); @@ -2975,20 +2975,20 @@ coap_handle_request_put_block(coap_context_t *context, #if COAP_Q_BLOCK_SUPPORT if (block_option == COAP_OPTION_Q_BLOCK1) { - if (total != p->total_len) { + if (total != lg_srcv->total_len) { coap_add_data(response, sizeof("Size1 mismatch")-1, (const uint8_t *)"Size1 mismatch"); response->code = COAP_RESPONSE_CODE(408); goto free_lg_srcv; } - coap_delete_bin_const(p->last_token); - p->last_token = coap_new_bin_const(pdu->actual_token.s, - pdu->actual_token.length); + coap_delete_bin_const(lg_srcv->last_token); + lg_srcv->last_token = coap_new_bin_const(pdu->actual_token.s, + pdu->actual_token.length); } #endif /* COAP_Q_BLOCK_SUPPORT */ - p->last_mid = pdu->mid; - p->last_type = pdu->type; + lg_srcv->last_mid = pdu->mid; + lg_srcv->last_type = pdu->type; chunk = (size_t)1 << (block.szx + 4); update_data = 0; @@ -2996,9 +2996,9 @@ coap_handle_request_put_block(coap_context_t *context, saved_offset = offset; while (offset < saved_offset + length) { - if (!check_if_received_block(&p->rec_blocks, block.num)) { + if (!check_if_received_block(&lg_srcv->rec_blocks, block.num)) { /* Update list of blocks received */ - if (!update_received_blocks(&p->rec_blocks, block.num)) { + if (!update_received_blocks(&lg_srcv->rec_blocks, block.num)) { coap_handle_event_lkd(context, COAP_EVENT_PARTIAL_BLOCK, session); coap_add_data(response, sizeof("Too many missing blocks")-1, (const uint8_t *)"Too many missing blocks"); @@ -3015,15 +3015,15 @@ coap_handle_request_put_block(coap_context_t *context, if (update_data) { /* Update saved data */ #if COAP_Q_BLOCK_SUPPORT - p->rec_blocks.processing_payload_set = + lg_srcv->rec_blocks.processing_payload_set = block.num / COAP_MAX_PAYLOADS(session); #endif /* COAP_Q_BLOCK_SUPPORT */ - if (p->total_len < saved_offset + length) { - p->total_len = saved_offset + length; + if (lg_srcv->total_len < saved_offset + length) { + lg_srcv->total_len = saved_offset + length; } - p->body_data = coap_block_build_body(p->body_data, length, data, - saved_offset, p->total_len); - if (!p->body_data) { + lg_srcv->body_data = coap_block_build_body(lg_srcv->body_data, length, data, + saved_offset, lg_srcv->total_len); + if (!lg_srcv->body_data) { coap_add_data(response, sizeof("Memory issue")-1, (const uint8_t *)"Memory issue"); response->code = COAP_RESPONSE_CODE(500); @@ -3032,23 +3032,23 @@ coap_handle_request_put_block(coap_context_t *context, } if (block.m || - !check_all_blocks_in(&p->rec_blocks, - (uint32_t)(p->total_len + chunk -1)/chunk)) { + !check_all_blocks_in(&lg_srcv->rec_blocks, + (uint32_t)(lg_srcv->total_len + chunk -1)/chunk)) { /* Not all the payloads of the body have arrived */ if (block.m) { uint8_t buf[4]; #if COAP_Q_BLOCK_SUPPORT if (block_option == COAP_OPTION_Q_BLOCK1) { - if (check_all_blocks_in(&p->rec_blocks, - (uint32_t)(p->total_len + chunk -1)/chunk)) { + if (check_all_blocks_in(&lg_srcv->rec_blocks, + (uint32_t)(lg_srcv->total_len + chunk -1)/chunk)) { goto give_app_data; } - if (p->rec_blocks.used == 1 && - (p->rec_blocks.range[0].end % COAP_MAX_PAYLOADS(session)) + 1 + if (lg_srcv->rec_blocks.used == 1 && + (lg_srcv->rec_blocks.range[0].end % COAP_MAX_PAYLOADS(session)) + 1 == COAP_MAX_PAYLOADS(session)) { /* Blocks could arrive in wrong order */ - block.num = p->rec_blocks.range[0].end; + block.num = lg_srcv->rec_blocks.range[0].end; } else { /* The remote end will be sending the next one unless this is a MAX_PAYLOADS and all previous have been received */ @@ -3073,8 +3073,8 @@ coap_handle_request_put_block(coap_context_t *context, * complete payload to application and acknowledge this current * block. */ - if (!check_all_blocks_in(&p->rec_blocks, - (uint32_t)(p->total_len + chunk -1)/chunk)) { + if (!check_all_blocks_in(&lg_srcv->rec_blocks, + (uint32_t)(lg_srcv->total_len + chunk -1)/chunk)) { /* Ask for the next block */ coap_insert_option(response, block_option, coap_encode_var_safe(buf, sizeof(buf), @@ -3094,8 +3094,8 @@ coap_handle_request_put_block(coap_context_t *context, tmp_pdu->code = COAP_RESPONSE_CODE(231); coap_send_internal(session, tmp_pdu); } - coap_update_token(response, p->last_token->length, p->last_token->s); - coap_update_token(pdu, p->last_token->length, p->last_token->s); + coap_update_token(response, lg_srcv->last_token->length, lg_srcv->last_token->s); + coap_update_token(pdu, lg_srcv->last_token->length, lg_srcv->last_token->s); /* Pass the assembled pdu and body to the application */ goto give_app_data; } @@ -3105,11 +3105,11 @@ coap_handle_request_put_block(coap_context_t *context, if (block_option != COAP_OPTION_Q_BLOCK1) { #endif /* COAP_Q_BLOCK_SUPPORT */ /* Last chunk - but not all in */ - coap_ticks(&p->last_used); - p->no_more_seen = 1; - coap_delete_bin_const(p->last_token); - p->last_token = coap_new_bin_const(pdu->actual_token.s, - pdu->actual_token.length); + coap_ticks(&lg_srcv->last_used); + lg_srcv->no_more_seen = 1; + coap_delete_bin_const(lg_srcv->last_token); + lg_srcv->last_token = coap_new_bin_const(pdu->actual_token.s, + pdu->actual_token.length); /* * Need to just ACK (no response code) to handle client's NSTART. @@ -3134,25 +3134,25 @@ coap_handle_request_put_block(coap_context_t *context, * Adjust all other information. */ give_app_data: - if (p->observe_set) { + if (lg_srcv->observe_set) { coap_update_option(pdu, COAP_OPTION_OBSERVE, - p->observe_length, p->observe); + lg_srcv->observe_length, lg_srcv->observe); } coap_remove_option(pdu, block_option); - pdu->body_data = p->body_data->s; - pdu->body_length = p->total_len; + pdu->body_data = lg_srcv->body_data->s; + pdu->body_length = lg_srcv->total_len; pdu->body_offset = 0; - pdu->body_total = p->total_len; + pdu->body_total = lg_srcv->total_len; coap_log_debug("Server app version of updated PDU\n"); coap_show_pdu(COAP_LOG_DEBUG, pdu); - *pfree_lg_srcv = p; + *pfree_lg_srcv = lg_srcv; call_app_handler: return 0; free_lg_srcv: - LL_DELETE(session->lg_srcv, p); - coap_block_delete_lg_srcv(session, p); + LL_DELETE(session->lg_srcv, lg_srcv); + coap_block_delete_lg_srcv(session, lg_srcv); skip_app_handler: return 1; @@ -3308,48 +3308,48 @@ track_echo(coap_session_t *session, coap_pdu_t *rcvd) { int coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, coap_pdu_t *rcvd) { - coap_lg_xmit_t *p; + coap_lg_xmit_t *lg_xmit; coap_lg_xmit_t *q; uint64_t token_match = STATE_TOKEN_BASE(coap_decode_var_bytes8(rcvd->actual_token.s, rcvd->actual_token.length)); coap_lg_crcv_t *lg_crcv = NULL; - LL_FOREACH_SAFE(session->lg_xmit, p, q) { - if (!COAP_PDU_IS_REQUEST(&p->pdu) || - (token_match != STATE_TOKEN_BASE(p->b.b1.state_token) && - !coap_binary_equal(&rcvd->actual_token, p->b.b1.app_token))) { + LL_FOREACH_SAFE(session->lg_xmit, lg_xmit, q) { + if (!COAP_PDU_IS_REQUEST(&lg_xmit->pdu) || + (token_match != STATE_TOKEN_BASE(lg_xmit->b.b1.state_token) && + !coap_binary_equal(&rcvd->actual_token, lg_xmit->b.b1.app_token))) { /* try out the next one */ continue; } /* lg_xmit found */ - size_t chunk = (size_t)1 << (p->blk_size + 4); + size_t chunk = (size_t)1 << (lg_xmit->blk_size + 4); coap_block_b_t block; if (COAP_RESPONSE_CLASS(rcvd->code) == 2 && - coap_get_block_b(session, rcvd, p->option, &block)) { + coap_get_block_b(session, rcvd, lg_xmit->option, &block)) { if (block.bert) { coap_log_debug("found Block option, block is BERT, block nr. %u (%zu)\n", - block.num, p->b.b1.bert_size); + block.num, lg_xmit->b.b1.bert_size); } else { coap_log_debug("found Block option, block size is %u, block nr. %u\n", 1 << (block.szx + 4), block.num); } - if (block.szx != p->blk_size) { - if (block.szx > p->blk_size) { + if (block.szx != lg_xmit->blk_size) { + if (block.szx > lg_xmit->blk_size) { coap_log_info("ignoring request to increase Block size, " "(%u > %u)\n", - 1 << (block.szx + 4), 1 << (p->blk_size + 4)); - } else if ((p->offset + chunk) % ((size_t)1 << (block.szx + 4)) == 0) { + 1 << (block.szx + 4), 1 << (lg_xmit->blk_size + 4)); + } else if ((lg_xmit->offset + chunk) % ((size_t)1 << (block.szx + 4)) == 0) { /* * Recompute the block number of the previous packet given the * new block size */ - block.num = (uint32_t)(((p->offset + chunk) >> (block.szx + 4)) - 1); - p->blk_size = block.szx; - chunk = (size_t)1 << (p->blk_size + 4); - p->offset = block.num * chunk; + block.num = (uint32_t)(((lg_xmit->offset + chunk) >> (block.szx + 4)) - 1); + lg_xmit->blk_size = block.szx; + chunk = (size_t)1 << (lg_xmit->blk_size + 4); + lg_xmit->offset = block.num * chunk; coap_log_debug("new Block size is %u, block number %u completed\n", 1 << (block.szx + 4), block.num); block.bert = 0; @@ -3358,14 +3358,14 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, coap_log_debug("ignoring request to increase Block size, " "next block is not aligned on requested block size boundary. " "(%zu x %u mod %u = %zu != 0)\n", - p->offset/chunk + 1, (1 << (p->blk_size + 4)), + lg_xmit->offset/chunk + 1, (1 << (lg_xmit->blk_size + 4)), (1 << (block.szx + 4)), - (p->offset + chunk) % ((size_t)1 << (block.szx + 4))); + (lg_xmit->offset + chunk) % ((size_t)1 << (block.szx + 4))); } } track_echo(session, rcvd); - if (p->last_block == (int)block.num && - p->option != COAP_OPTION_Q_BLOCK1) { + if (lg_xmit->last_block == (int)block.num && + lg_xmit->option != COAP_OPTION_Q_BLOCK1) { /* * Duplicate Block1 ACK * @@ -3379,25 +3379,25 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, return 1; } if (block.bert) - block.num += (unsigned int)(p->b.b1.bert_size / 1024 - 1); - p->last_block = block.num; - p->offset = (block.num + 1) * chunk; - if (p->offset < p->length) { + block.num += (unsigned int)(lg_xmit->b.b1.bert_size / 1024 - 1); + lg_xmit->last_block = block.num; + lg_xmit->offset = (block.num + 1) * chunk; + if (lg_xmit->offset < lg_xmit->length) { /* Build the next PDU request based off the skeletal PDU */ uint8_t buf[8]; coap_pdu_t *pdu; - uint64_t token = STATE_TOKEN_FULL(p->b.b1.state_token, ++p->b.b1.count); + uint64_t token = STATE_TOKEN_FULL(lg_xmit->b.b1.state_token, ++lg_xmit->b.b1.count); size_t len = coap_encode_var_safe8(buf, sizeof(token), token); - if (p->pdu.code == COAP_REQUEST_CODE_FETCH) { + if (lg_xmit->pdu.code == COAP_REQUEST_CODE_FETCH) { /* Need to handle Observe for large FETCH */ LL_FOREACH(session->lg_crcv, lg_crcv) { - if (coap_binary_equal(p->b.b1.app_token, lg_crcv->app_token)) { + if (coap_binary_equal(lg_xmit->b.b1.app_token, lg_crcv->app_token)) { coap_bin_const_t *new_token; coap_bin_const_t ctoken = { len, buf }; /* Need to save/restore Observe Token for large FETCH */ - new_token = track_fetch_observe(&p->pdu, lg_crcv, block.num + 1, + new_token = track_fetch_observe(&lg_xmit->pdu, lg_crcv, block.num + 1, &ctoken); if (new_token) { assert(len <= sizeof(buf)); @@ -3408,7 +3408,7 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, } } } - pdu = coap_pdu_duplicate_lkd(&p->pdu, session, len, buf, NULL); + pdu = coap_pdu_duplicate_lkd(&lg_xmit->pdu, session, len, buf, NULL); if (!pdu) goto fail_body; @@ -3416,12 +3416,12 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, if (block.bert) { size_t token_options = pdu->data ? (size_t)(pdu->data - pdu->token) : pdu->used_size; - block.m = (p->length - p->offset) > + block.m = (lg_xmit->length - lg_xmit->offset) > ((pdu->max_size - token_options) /1024) * 1024; } else { - block.m = (p->offset + chunk) < p->length; + block.m = (lg_xmit->offset + chunk) < lg_xmit->length; } - coap_update_option(pdu, p->option, + coap_update_option(pdu, lg_xmit->option, coap_encode_var_safe(buf, sizeof(buf), (block.num << 4) | (block.m << 3) | @@ -3429,14 +3429,14 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, buf); if (!coap_add_block_b_data(pdu, - p->length, - p->data, + lg_xmit->length, + lg_xmit->data, &block)) goto fail_body; - p->b.b1.bert_size = block.chunk_size; - coap_ticks(&p->last_sent); + lg_xmit->b.b1.bert_size = block.chunk_size; + coap_ticks(&lg_xmit->last_sent); #if COAP_Q_BLOCK_SUPPORT - if (p->option == COAP_OPTION_Q_BLOCK1 && + if (lg_xmit->option == COAP_OPTION_Q_BLOCK1 && pdu->type == COAP_MESSAGE_NON) { if (coap_send_q_block1(session, block, pdu, COAP_SEND_INC_PDU) == COAP_INVALID_MID) @@ -3460,10 +3460,10 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, coap_opt_t *obs_opt; int observe_action = -1; - if (p->pdu.code != COAP_REQUEST_CODE_FETCH) { + if (lg_xmit->pdu.code != COAP_REQUEST_CODE_FETCH) { goto lg_xmit_finished; } - obs_opt = coap_check_option(&p->pdu, + obs_opt = coap_check_option(&lg_xmit->pdu, COAP_OPTION_OBSERVE, &opt_iter); if (obs_opt) { @@ -3481,7 +3481,7 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, } goto lg_xmit_finished; } else if (rcvd->code == COAP_RESPONSE_CODE(401)) { - if (check_freshness(session, rcvd, sent, p, NULL)) + if (check_freshness(session, rcvd, sent, lg_xmit, NULL)) return 1; #if COAP_Q_BLOCK_SUPPORT } else if (rcvd->code == COAP_RESPONSE_CODE(402)) { @@ -3490,7 +3490,7 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, coap_get_block_b(session, rcvd, COAP_OPTION_Q_BLOCK1, &block)) return 1; } else if (rcvd->code == COAP_RESPONSE_CODE(408) && - p->option == COAP_OPTION_Q_BLOCK1) { + lg_xmit->option == COAP_OPTION_Q_BLOCK1) { size_t length; const uint8_t *data; coap_opt_iterator_t opt_iter; @@ -3529,18 +3529,18 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, coap_log_debug("Q-Block1: Missing block %d\n", block.num); if (block.num > (1 << 20) -1) goto fail_cbor; - block.m = (block.num + 1) * chunk < p->length; - block.szx = p->blk_size; + block.m = (block.num + 1) * chunk < lg_xmit->length; + block.szx = lg_xmit->blk_size; /* Build the next PDU request based off the skeletal PDU */ - token = STATE_TOKEN_FULL(p->b.b1.state_token,++p->b.b1.count); + token = STATE_TOKEN_FULL(lg_xmit->b.b1.state_token,++lg_xmit->b.b1.count); ltoken_length = coap_encode_var_safe8(ltoken, sizeof(token), token); - pdu = coap_pdu_duplicate_lkd(&p->pdu, session, ltoken_length, + pdu = coap_pdu_duplicate_lkd(&lg_xmit->pdu, session, ltoken_length, ltoken, NULL); if (!pdu) goto fail_body; - coap_update_option(pdu, p->option, + coap_update_option(pdu, lg_xmit->option, coap_encode_var_safe(buf, sizeof(buf), (block.num << 4) | (block.m << 3) | @@ -3548,8 +3548,8 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, buf); if (!coap_add_block(pdu, - p->length, - p->data, + lg_xmit->length, + lg_xmit->data, block.num, block.szx)) goto fail_body; @@ -3573,20 +3573,20 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, lg_xmit_finished: if (session->lg_crcv) { LL_FOREACH(session->lg_crcv, lg_crcv) { - if (STATE_TOKEN_BASE(p->b.b1.state_token) == + if (STATE_TOKEN_BASE(lg_xmit->b.b1.state_token) == STATE_TOKEN_BASE(lg_crcv->state_token)) { /* In case of observe */ - lg_crcv->state_token = p->b.b1.state_token; - lg_crcv->retry_counter = p->b.b1.count; + lg_crcv->state_token = lg_xmit->b.b1.state_token; + lg_crcv->retry_counter = lg_xmit->b.b1.count; break; } } } if (!lg_crcv) { /* need to put back original token into rcvd */ - if (p->b.b1.app_token) - coap_update_token(rcvd, p->b.b1.app_token->length, - p->b.b1.app_token->s); + if (lg_xmit->b.b1.app_token) + coap_update_token(rcvd, lg_xmit->b.b1.app_token->length, + lg_xmit->b.b1.app_token->s); coap_log_debug("Client app version of updated PDU\n"); coap_show_pdu(COAP_LOG_DEBUG, rcvd); } else { @@ -3595,15 +3595,15 @@ coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, 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 (lg_xmit->b.b1.app_token) + coap_update_token(sent, lg_xmit->b.b1.app_token->length, + lg_xmit->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); + LL_DELETE(session->lg_xmit, lg_xmit); + coap_block_delete_lg_xmit(session, lg_xmit); return 0; } #endif /* COAP_CLIENT_SUPPORT */ @@ -3667,7 +3667,7 @@ coap_handle_response_get_block(coap_context_t *context, coap_pdu_t *sent, coap_pdu_t *rcvd, coap_recurse_t recursive) { - coap_lg_crcv_t *p; + coap_lg_crcv_t *lg_crcv; coap_block_b_t block; #if COAP_Q_BLOCK_SUPPORT coap_block_b_t qblock; @@ -3685,13 +3685,13 @@ coap_handle_response_get_block(coap_context_t *context, #if COAP_Q_BLOCK_SUPPORT memset(&qblock, 0, sizeof(qblock)); #endif /* COAP_Q_BLOCK_SUPPORT */ - LL_FOREACH(session->lg_crcv, p) { + LL_FOREACH(session->lg_crcv, lg_crcv) { size_t chunk = 0; uint8_t buf[8]; coap_opt_iterator_t opt_iter; - if (token_match != STATE_TOKEN_BASE(p->state_token) && - !coap_binary_equal(&rcvd->actual_token, p->app_token)) { + if (token_match != STATE_TOKEN_BASE(lg_crcv->state_token) && + !coap_binary_equal(&rcvd->actual_token, lg_crcv->app_token)) { /* try out the next one */ continue; } @@ -3767,43 +3767,43 @@ coap_handle_response_get_block(coap_context_t *context, } saved_offset = offset; - if (p->initial) { + if (lg_crcv->initial) { #if COAP_Q_BLOCK_SUPPORT reinit: #endif /* COAP_Q_BLOCK_SUPPORT */ - p->initial = 0; - if (p->body_data) { - coap_free_type(COAP_STRING, p->body_data); - p->body_data = NULL; + lg_crcv->initial = 0; + if (lg_crcv->body_data) { + coap_free_type(COAP_STRING, lg_crcv->body_data); + lg_crcv->body_data = NULL; } if (etag_opt) { - p->etag_length = coap_opt_length(etag_opt); - memcpy(p->etag, coap_opt_value(etag_opt), p->etag_length); - p->etag_set = 1; + lg_crcv->etag_length = coap_opt_length(etag_opt); + memcpy(lg_crcv->etag, coap_opt_value(etag_opt), lg_crcv->etag_length); + lg_crcv->etag_set = 1; } else { - p->etag_set = 0; + lg_crcv->etag_set = 0; } - p->total_len = size2; - p->content_format = fmt; - p->szx = block.szx; - p->block_option = block_opt; - p->last_type = rcvd->type; - p->rec_blocks.used = 0; + lg_crcv->total_len = size2; + lg_crcv->content_format = fmt; + lg_crcv->szx = block.szx; + lg_crcv->block_option = block_opt; + lg_crcv->last_type = rcvd->type; + lg_crcv->rec_blocks.used = 0; #if COAP_Q_BLOCK_SUPPORT - p->rec_blocks.processing_payload_set = 0; + lg_crcv->rec_blocks.processing_payload_set = 0; #endif /* COAP_Q_BLOCK_SUPPORT */ } - if (p->total_len < size2) - p->total_len = size2; + if (lg_crcv->total_len < size2) + lg_crcv->total_len = size2; if (etag_opt) { if (!full_match(coap_opt_value(etag_opt), coap_opt_length(etag_opt), - p->etag, p->etag_length)) { + lg_crcv->etag, lg_crcv->etag_length)) { /* body of data has changed - need to restart request */ coap_pdu_t *pdu; - uint64_t token = STATE_TOKEN_FULL(p->state_token, - ++p->retry_counter); + uint64_t token = STATE_TOKEN_FULL(lg_crcv->state_token, + ++lg_crcv->retry_counter); size_t len = coap_encode_var_safe8(buf, sizeof(token), token); coap_opt_filter_t drop_options; @@ -3816,14 +3816,14 @@ coap_handle_response_get_block(coap_context_t *context, if (!(session->block_mode & COAP_BLOCK_SINGLE_BODY)) coap_handle_event_lkd(context, COAP_EVENT_PARTIAL_BLOCK, session); - p->initial = 1; - coap_free_type(COAP_STRING, p->body_data); - p->body_data = NULL; + lg_crcv->initial = 1; + coap_free_type(COAP_STRING, lg_crcv->body_data); + lg_crcv->body_data = NULL; coap_session_new_token(session, &len, buf); memset(&drop_options, 0, sizeof(coap_opt_filter_t)); coap_option_filter_set(&drop_options, COAP_OPTION_OBSERVE); - pdu = coap_pdu_duplicate_lkd(&p->pdu, session, len, buf, &drop_options); + pdu = coap_pdu_duplicate_lkd(&lg_crcv->pdu, session, len, buf, &drop_options); if (!pdu) goto fail_resp; @@ -3837,18 +3837,18 @@ coap_handle_response_get_block(coap_context_t *context, goto skip_app_handler; } - } else if (p->etag_set) { + } else if (lg_crcv->etag_set) { /* Cannot handle this change in ETag to not being there */ coap_log_warn("Not all blocks have ETag option\n"); goto fail_resp; } - if (fmt != p->content_format) { + if (fmt != lg_crcv->content_format) { coap_log_warn("Content-Format option mismatch\n"); goto fail_resp; } #if COAP_Q_BLOCK_SUPPORT - if (block_opt == COAP_OPTION_Q_BLOCK2 && size2 != p->total_len) { + if (block_opt == COAP_OPTION_Q_BLOCK2 && size2 != lg_crcv->total_len) { coap_log_warn("Size2 option mismatch\n"); goto fail_resp; } @@ -3858,16 +3858,16 @@ coap_handle_response_get_block(coap_context_t *context, COAP_OPTION_OBSERVE, &opt_iter); if (obs_opt) { - p->observe_length = min(coap_opt_length(obs_opt), 3); - memcpy(p->observe, coap_opt_value(obs_opt), p->observe_length); - p->observe_set = 1; + lg_crcv->observe_length = min(coap_opt_length(obs_opt), 3); + memcpy(lg_crcv->observe, coap_opt_value(obs_opt), lg_crcv->observe_length); + lg_crcv->observe_set = 1; } else { - p->observe_set = 0; + lg_crcv->observe_set = 0; } } updated_block = 0; while (offset < saved_offset + length) { - if (!check_if_received_block(&p->rec_blocks, block.num)) { + if (!check_if_received_block(&lg_crcv->rec_blocks, block.num)) { #if COAP_Q_BLOCK_SUPPORT uint32_t this_payload_set = block.num / COAP_MAX_PAYLOADS(session); #endif /* COAP_Q_BLOCK_SUPPORT */ @@ -3875,15 +3875,15 @@ coap_handle_response_get_block(coap_context_t *context, coap_log_debug("found Block option, block size is %u, block nr. %u\n", 1 << (block.szx + 4), block.num); #if COAP_Q_BLOCK_SUPPORT - if (block_opt == COAP_OPTION_Q_BLOCK2 && p->rec_blocks.used && - this_payload_set > p->rec_blocks.processing_payload_set && - this_payload_set != p->rec_blocks.latest_payload_set) { - coap_request_missing_q_block2(session, p); + if (block_opt == COAP_OPTION_Q_BLOCK2 && lg_crcv->rec_blocks.used && + this_payload_set > lg_crcv->rec_blocks.processing_payload_set && + this_payload_set != lg_crcv->rec_blocks.latest_payload_set) { + coap_request_missing_q_block2(session, lg_crcv); } - p->rec_blocks.latest_payload_set = this_payload_set; + lg_crcv->rec_blocks.latest_payload_set = this_payload_set; #endif /* COAP_Q_BLOCK_SUPPORT */ /* Update list of blocks received */ - if (!update_received_blocks(&p->rec_blocks, block.num)) { + if (!update_received_blocks(&lg_crcv->rec_blocks, block.num)) { coap_handle_event_lkd(context, COAP_EVENT_PARTIAL_BLOCK, session); goto fail_resp; } @@ -3901,13 +3901,13 @@ coap_handle_response_get_block(coap_context_t *context, if (size2 < saved_offset + length) { size2 = saved_offset + length; } - p->body_data = coap_block_build_body(p->body_data, length, data, - saved_offset, size2); - if (p->body_data == NULL) { + lg_crcv->body_data = coap_block_build_body(lg_crcv->body_data, length, data, + saved_offset, size2); + if (lg_crcv->body_data == NULL) { goto fail_resp; } } - if (block.m || !check_all_blocks_in(&p->rec_blocks, + if (block.m || !check_all_blocks_in(&lg_crcv->rec_blocks, (size2 + chunk -1) / chunk)) { /* Not all the payloads of the body have arrived */ size_t len; @@ -3918,20 +3918,20 @@ coap_handle_response_get_block(coap_context_t *context, #if COAP_Q_BLOCK_SUPPORT if (block_opt == COAP_OPTION_Q_BLOCK2) { /* Blocks could arrive in wrong order */ - if (check_all_blocks_in(&p->rec_blocks, + if (check_all_blocks_in(&lg_crcv->rec_blocks, (size2 + chunk -1) / chunk)) { goto give_to_app; } if (check_all_blocks_in_for_payload_set(session, - &p->rec_blocks)) { - block.num = p->rec_blocks.range[0].end; + &lg_crcv->rec_blocks)) { + block.num = lg_crcv->rec_blocks.range[0].end; /* Now requesting next payload */ - p->rec_blocks.processing_payload_set = + lg_crcv->rec_blocks.processing_payload_set = block.num / COAP_MAX_PAYLOADS(session) + 1; if (check_any_blocks_next_payload_set(session, - &p->rec_blocks)) { + &lg_crcv->rec_blocks)) { /* Need to ask for them individually */ - coap_request_missing_q_block2(session, p); + coap_request_missing_q_block2(session, lg_crcv); goto skip_app_handler; } } else { @@ -3948,9 +3948,9 @@ coap_handle_response_get_block(coap_context_t *context, block.m = 0; /* Ask for the next block */ - token = STATE_TOKEN_FULL(p->state_token, ++p->retry_counter); + token = STATE_TOKEN_FULL(lg_crcv->state_token, ++lg_crcv->retry_counter); len = coap_encode_var_safe8(buf, sizeof(token), token); - pdu = coap_pdu_duplicate_lkd(&p->pdu, session, len, buf, NULL); + pdu = coap_pdu_duplicate_lkd(&lg_crcv->pdu, session, len, buf, NULL); if (!pdu) goto fail_resp; @@ -3967,7 +3967,7 @@ coap_handle_response_get_block(coap_context_t *context, buf); if (session->block_mode & COAP_BLOCK_STLESS_FETCH && pdu->code == COAP_REQUEST_CODE_FETCH) { - (void)coap_get_data(&p->pdu, &length, &data); + (void)coap_get_data(&lg_crcv->pdu, &length, &data); coap_add_data_large_internal(session, NULL, pdu, NULL, NULL, -1, 0, length, data, NULL, NULL, 0, 0); } if (coap_send_internal(session, pdu) == COAP_INVALID_MID) @@ -3977,11 +3977,11 @@ coap_handle_response_get_block(coap_context_t *context, goto skip_app_handler; /* need to put back original token into rcvd */ - coap_update_token(rcvd, p->app_token->length, p->app_token->s); + coap_update_token(rcvd, lg_crcv->app_token->length, lg_crcv->app_token->s); rcvd->body_offset = saved_offset; #if COAP_Q_BLOCK_SUPPORT rcvd->body_total = block_opt == COAP_OPTION_Q_BLOCK2 ? - p->total_len : size2; + lg_crcv->total_len : size2; #else /* ! COAP_Q_BLOCK_SUPPORT */ rcvd->body_total = size2; #endif /* ! COAP_Q_BLOCK_SUPPORT */ @@ -3990,10 +3990,10 @@ coap_handle_response_get_block(coap_context_t *context, 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 (lg_crcv->app_token) + coap_update_token(sent, lg_crcv->app_token->length, + lg_crcv->app_token->s); + coap_remove_option(sent, lg_crcv->block_option); } goto call_app_handler; } @@ -4003,14 +4003,14 @@ coap_handle_response_get_block(coap_context_t *context, if ((session->block_mode & COAP_SINGLE_BLOCK_OR_Q) || block.bert) { /* Pretend that there is no block */ coap_remove_option(rcvd, block_opt); - if (p->observe_set) { + if (lg_crcv->observe_set) { coap_update_option(rcvd, COAP_OPTION_OBSERVE, - p->observe_length, p->observe); + lg_crcv->observe_length, lg_crcv->observe); } - rcvd->body_data = p->body_data->s; + rcvd->body_data = lg_crcv->body_data->s; #if COAP_Q_BLOCK_SUPPORT rcvd->body_length = block_opt == COAP_OPTION_Q_BLOCK2 ? - p->total_len : saved_offset + length; + lg_crcv->total_len : saved_offset + length; #else /* ! COAP_Q_BLOCK_SUPPORT */ rcvd->body_length = saved_offset + length; #endif /* ! COAP_Q_BLOCK_SUPPORT */ @@ -4020,7 +4020,7 @@ coap_handle_response_get_block(coap_context_t *context, rcvd->body_offset = saved_offset; #if COAP_Q_BLOCK_SUPPORT rcvd->body_total = block_opt == COAP_OPTION_Q_BLOCK2 ? - p->total_len : size2; + lg_crcv->total_len : size2; #else /* ! COAP_Q_BLOCK_SUPPORT */ rcvd->body_total = size2; #endif /* ! COAP_Q_BLOCK_SUPPORT */ @@ -4029,17 +4029,17 @@ coap_handle_response_get_block(coap_context_t *context, coap_response_t ret; /* need to put back original token into rcvd */ - if (!coap_binary_equal(&rcvd->actual_token, p->app_token)) { - coap_update_token(rcvd, p->app_token->length, p->app_token->s); + if (!coap_binary_equal(&rcvd->actual_token, lg_crcv->app_token)) { + coap_update_token(rcvd, lg_crcv->app_token->length, lg_crcv->app_token->s); 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 (lg_crcv->app_token) + coap_update_token(sent, lg_crcv->app_token->length, + lg_crcv->app_token->s); + coap_remove_option(sent, lg_crcv->block_option); } coap_lock_callback_ret_release(ret, session->context, context->response_handler(session, sent, rcvd, @@ -4055,34 +4055,34 @@ coap_handle_response_get_block(coap_context_t *context, coap_send_ack_lkd(session, rcvd); } ack_rst_sent = 1; - if (p->observe_set == 0) { + if (lg_crcv->observe_set == 0) { /* Expire this entry */ - LL_DELETE(session->lg_crcv, p); - coap_block_delete_lg_crcv(session, p); + LL_DELETE(session->lg_crcv, lg_crcv); + coap_block_delete_lg_crcv(session, lg_crcv); goto skip_app_handler; } /* Set up for the next data body as observing */ - p->initial = 1; - if (p->body_data) { - coap_free_type(COAP_STRING, p->body_data); - p->body_data = NULL; + lg_crcv->initial = 1; + if (lg_crcv->body_data) { + coap_free_type(COAP_STRING, lg_crcv->body_data); + lg_crcv->body_data = NULL; } } - coap_ticks(&p->last_used); + coap_ticks(&lg_crcv->last_used); goto skip_app_handler; } else { coap_opt_t *obs_opt = coap_check_option(rcvd, COAP_OPTION_OBSERVE, &opt_iter); if (obs_opt) { - p->observe_length = min(coap_opt_length(obs_opt), 3); - memcpy(p->observe, coap_opt_value(obs_opt), p->observe_length); - p->observe_set = 1; + lg_crcv->observe_length = min(coap_opt_length(obs_opt), 3); + memcpy(lg_crcv->observe, coap_opt_value(obs_opt), lg_crcv->observe_length); + lg_crcv->observe_set = 1; } else { - p->observe_set = 0; - if (!coap_binary_equal(&rcvd->actual_token, p->app_token)) { + lg_crcv->observe_set = 0; + if (!coap_binary_equal(&rcvd->actual_token, lg_crcv->app_token)) { /* need to put back original token into rcvd */ - coap_update_token(rcvd, p->app_token->length, p->app_token->s); + coap_update_token(rcvd, lg_crcv->app_token->length, lg_crcv->app_token->s); coap_log_debug("PDU presented to app.\n"); coap_show_pdu(COAP_LOG_DEBUG, rcvd); } @@ -4090,14 +4090,14 @@ coap_handle_response_get_block(coap_context_t *context, goto expire_lg_crcv; } } - coap_ticks(&p->last_used); + coap_ticks(&lg_crcv->last_used); } else if (rcvd->code == COAP_RESPONSE_CODE(401)) { #if COAP_OSCORE_SUPPORT if (check_freshness(session, rcvd, (session->oscore_encryption == 0) ? sent : NULL, - NULL, p)) + NULL, lg_crcv)) #else /* !COAP_OSCORE_SUPPORT */ - if (check_freshness(session, rcvd, sent, NULL, p)) + if (check_freshness(session, rcvd, sent, NULL, lg_crcv)) #endif /* !COAP_OSCORE_SUPPORT */ goto skip_app_handler; goto expire_lg_crcv; @@ -4105,16 +4105,16 @@ coap_handle_response_get_block(coap_context_t *context, /* Not 2.xx or 4.01 - assume it is a failure of some sort */ goto expire_lg_crcv; } - if (!block.m && !p->observe_set) { + if (!block.m && !lg_crcv->observe_set) { fail_resp: /* lg_crcv no longer required - cache it for 1 sec */ - coap_ticks(&p->last_used); - p->last_used = p->last_used - COAP_MAX_TRANSMIT_WAIT_TICKS(session) + - COAP_TICKS_PER_SECOND; + coap_ticks(&lg_crcv->last_used); + lg_crcv->last_used = lg_crcv->last_used - COAP_MAX_TRANSMIT_WAIT_TICKS(session) + + COAP_TICKS_PER_SECOND; } /* need to put back original token into rcvd */ - if (!coap_binary_equal(&rcvd->actual_token, p->app_token)) { - coap_update_token(rcvd, p->app_token->length, p->app_token->s); + if (!coap_binary_equal(&rcvd->actual_token, lg_crcv->app_token)) { + coap_update_token(rcvd, lg_crcv->app_token->length, lg_crcv->app_token->s); coap_log_debug("Client app version of updated PDU (3)\n"); coap_show_pdu(COAP_LOG_DEBUG, rcvd); } @@ -4122,7 +4122,7 @@ coap_handle_response_get_block(coap_context_t *context, } /* LL_FOREACH() */ /* Check if receiving a block response and if blocks can be set up */ - if (recursive == COAP_RECURSE_OK && !p) { + if (recursive == COAP_RECURSE_OK && !lg_crcv) { if (!sent) { if (coap_get_block_b(session, rcvd, COAP_OPTION_BLOCK2, &block) #if COAP_Q_BLOCK_SUPPORT @@ -4165,7 +4165,7 @@ coap_handle_response_get_block(coap_context_t *context, } #endif /* COAP_Q_BLOCK_SUPPORT */ if (have_block) { - coap_lg_crcv_t *lg_crcv = coap_block_new_lg_crcv(session, sent, NULL); + lg_crcv = coap_block_new_lg_crcv(session, sent, NULL); if (lg_crcv) { LL_PREPEND(session->lg_crcv, lg_crcv); @@ -4175,7 +4175,7 @@ coap_handle_response_get_block(coap_context_t *context, } track_echo(session, rcvd); } else if (rcvd->code == COAP_RESPONSE_CODE(401)) { - coap_lg_crcv_t *lg_crcv = coap_block_new_lg_crcv(session, sent, NULL); + lg_crcv = coap_block_new_lg_crcv(session, sent, NULL); if (lg_crcv) { LL_PREPEND(session->lg_crcv, lg_crcv); @@ -4188,22 +4188,22 @@ coap_handle_response_get_block(coap_context_t *context, expire_lg_crcv: /* need to put back original token into rcvd */ - if (!coap_binary_equal(&rcvd->actual_token, p->app_token)) { - coap_update_token(rcvd, p->app_token->length, p->app_token->s); + if (!coap_binary_equal(&rcvd->actual_token, lg_crcv->app_token)) { + coap_update_token(rcvd, lg_crcv->app_token->length, lg_crcv->app_token->s); 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 (lg_crcv->app_token) + coap_update_token(sent, lg_crcv->app_token->length, + lg_crcv->app_token->s); + coap_remove_option(sent, lg_crcv->block_option); } /* Expire this entry */ - LL_DELETE(session->lg_crcv, p); - coap_block_delete_lg_crcv(session, p); + LL_DELETE(session->lg_crcv, lg_crcv); + coap_block_delete_lg_crcv(session, lg_crcv); call_app_handler: return 0;