Commit ccbd2dc8 authored by Kishen Maloor's avatar Kishen Maloor

coap:fix handling of last block1/block2 CON res

Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
parent e2d38bd7
......@@ -826,8 +826,8 @@ coap_tcp_set_header_fields(void *packet, uint8_t *num_extended_length_bytes,
coap_pkt->buffer[0] = 0x00;
coap_pkt->buffer[0] |=
COAP_TCP_HEADER_LEN_MASK & (*len) << COAP_TCP_HEADER_LEN_POSITION;
coap_pkt->buffer[0] |= COAP_HEADER_TOKEN_LEN_MASK &
(coap_pkt->token_len)
coap_pkt->buffer[0] |=
COAP_HEADER_TOKEN_LEN_MASK & (coap_pkt->token_len)
<< COAP_HEADER_TOKEN_LEN_POSITION;
int i = 0;
......@@ -977,10 +977,10 @@ coap_udp_set_header_fields(void *packet)
coap_pkt->buffer[0] = 0x00;
coap_pkt->buffer[0] |= COAP_HEADER_VERSION_MASK &
(coap_pkt->version) << COAP_HEADER_VERSION_POSITION;
coap_pkt->buffer[0] |= COAP_HEADER_TYPE_MASK & (coap_pkt->type)
<< COAP_HEADER_TYPE_POSITION;
coap_pkt->buffer[0] |=
COAP_HEADER_TYPE_MASK & (coap_pkt->type) << COAP_HEADER_TYPE_POSITION;
coap_pkt->buffer[0] |= COAP_HEADER_TOKEN_LEN_MASK &
(coap_pkt->token_len)
COAP_HEADER_TOKEN_LEN_MASK & (coap_pkt->token_len)
<< COAP_HEADER_TOKEN_LEN_POSITION;
coap_pkt->buffer[1] = coap_pkt->code;
coap_pkt->buffer[2] = (uint8_t)((coap_pkt->mid) >> 8);
......@@ -1302,7 +1302,6 @@ coap_get_header_accept(void *packet, unsigned int *accept)
*accept = coap_pkt->accept;
return 1;
}
#ifdef OC_CLIENT
int
coap_set_header_accept(void *packet, unsigned int accept)
{
......@@ -1312,7 +1311,6 @@ coap_set_header_accept(void *packet, unsigned int accept)
SET_OPTION(coap_pkt, COAP_OPTION_ACCEPT);
return 1;
}
#endif
/*---------------------------------------------------------------------------*/
#if 0
int coap_get_header_max_age(void *packet, uint32_t *age)
......
......@@ -316,15 +316,17 @@ coap_receive(oc_message_t *msg)
goto send_message;
} else {
OC_DBG("received all blocks for payload");
unsigned int cf = 0;
int cf_was_set = coap_get_header_content_format(response, &cf);
if (message->type == COAP_TYPE_CON) {
coap_send_empty_ack(message->mid, &msg->endpoint);
}
coap_udp_init_message(response, COAP_TYPE_CON, CONTENT_2_05,
response->mid);
coap_get_mid());
transaction->mid = response->mid;
coap_set_header_block1(response, block1_num, block1_more,
block1_size);
if (cf_was_set) {
coap_set_header_content_format(response, cf);
}
coap_set_header_content_format(response,
APPLICATION_VND_OCF_CBOR);
coap_set_header_accept(response, APPLICATION_VND_OCF_CBOR);
request_buffer->payload_size =
request_buffer->next_block_offset;
request_buffer->ref_count = 0;
......@@ -336,12 +338,6 @@ coap_receive(oc_message_t *msg)
goto init_reset_message;
} else if (block2) {
OC_DBG("processing block2 option");
unsigned int accept = 0;
if (coap_get_header_accept(message, &accept) == 1) {
coap_set_header_content_format(response, accept);
} else {
coap_set_header_content_format(response, APPLICATION_VND_OCF_CBOR);
}
response_buffer = oc_blockwise_find_response_buffer(
href, href_len, &msg->endpoint, message->code, message->uri_query,
message->uri_query_len, OC_BLOCKWISE_SERVER);
......@@ -364,14 +360,16 @@ coap_receive(oc_message_t *msg)
? 1
: 0;
if (more == 0) {
unsigned int cf = 0;
int cf_was_set = coap_get_header_content_format(response, &cf);
coap_udp_init_message(response, COAP_TYPE_CON, CONTENT_2_05,
response->mid);
if (cf_was_set) {
coap_set_header_content_format(response, cf);
if (message->type == COAP_TYPE_CON) {
coap_send_empty_ack(message->mid, &msg->endpoint);
}
coap_udp_init_message(response, COAP_TYPE_CON, CONTENT_2_05,
coap_get_mid());
transaction->mid = response->mid;
coap_set_header_accept(response, APPLICATION_VND_OCF_CBOR);
}
coap_set_header_content_format(response,
APPLICATION_VND_OCF_CBOR);
coap_set_payload(response, payload, payload_size);
coap_set_header_block2(response, block2_num, more, block2_size);
oc_blockwise_response_state_t *response_state =
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment