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
...@@ -641,7 +641,7 @@ coap_parse_token_option(void *packet, uint8_t *data, uint32_t data_len, ...@@ -641,7 +641,7 @@ coap_parse_token_option(void *packet, uint8_t *data, uint32_t data_len,
#ifdef OC_SPEC_VER_OIC #ifdef OC_SPEC_VER_OIC
&& coap_pkt->content_format != APPLICATION_CBOR && coap_pkt->content_format != APPLICATION_CBOR
#endif /* OC_SPEC_VER_OIC */ #endif /* OC_SPEC_VER_OIC */
) )
return UNSUPPORTED_MEDIA_TYPE_4_15; return UNSUPPORTED_MEDIA_TYPE_4_15;
break; break;
case COAP_OPTION_MAX_AGE: case COAP_OPTION_MAX_AGE:
...@@ -665,7 +665,7 @@ coap_parse_token_option(void *packet, uint8_t *data, uint32_t data_len, ...@@ -665,7 +665,7 @@ coap_parse_token_option(void *packet, uint8_t *data, uint32_t data_len,
#ifdef OC_SPEC_VER_OIC #ifdef OC_SPEC_VER_OIC
&& coap_pkt->accept != APPLICATION_CBOR && coap_pkt->accept != APPLICATION_CBOR
#endif /* OC_SPEC_VER_OIC */ #endif /* OC_SPEC_VER_OIC */
) )
return NOT_ACCEPTABLE_4_06; return NOT_ACCEPTABLE_4_06;
break; break;
#if 0 #if 0
...@@ -796,7 +796,7 @@ coap_parse_token_option(void *packet, uint8_t *data, uint32_t data_len, ...@@ -796,7 +796,7 @@ coap_parse_token_option(void *packet, uint8_t *data, uint32_t data_len,
#ifdef OC_SPEC_VER_OIC #ifdef OC_SPEC_VER_OIC
&& version != OIC_VER_1_1_0 && version != OIC_VER_1_1_0
#endif /* OC_SPEC_VER_OIC */ #endif /* OC_SPEC_VER_OIC */
) { ) {
OC_WRN("Unsupported version %d %u", option_number, version); OC_WRN("Unsupported version %d %u", option_number, version);
return UNSUPPORTED_MEDIA_TYPE_4_15; return UNSUPPORTED_MEDIA_TYPE_4_15;
} }
...@@ -826,9 +826,9 @@ coap_tcp_set_header_fields(void *packet, uint8_t *num_extended_length_bytes, ...@@ -826,9 +826,9 @@ coap_tcp_set_header_fields(void *packet, uint8_t *num_extended_length_bytes,
coap_pkt->buffer[0] = 0x00; coap_pkt->buffer[0] = 0x00;
coap_pkt->buffer[0] |= coap_pkt->buffer[0] |=
COAP_TCP_HEADER_LEN_MASK & (*len) << COAP_TCP_HEADER_LEN_POSITION; COAP_TCP_HEADER_LEN_MASK & (*len) << COAP_TCP_HEADER_LEN_POSITION;
coap_pkt->buffer[0] |= COAP_HEADER_TOKEN_LEN_MASK & coap_pkt->buffer[0] |=
(coap_pkt->token_len) COAP_HEADER_TOKEN_LEN_MASK & (coap_pkt->token_len)
<< COAP_HEADER_TOKEN_LEN_POSITION; << COAP_HEADER_TOKEN_LEN_POSITION;
int i = 0; int i = 0;
for (i = 1; i <= *num_extended_length_bytes; i++) { for (i = 1; i <= *num_extended_length_bytes; i++) {
...@@ -977,11 +977,11 @@ coap_udp_set_header_fields(void *packet) ...@@ -977,11 +977,11 @@ coap_udp_set_header_fields(void *packet)
coap_pkt->buffer[0] = 0x00; coap_pkt->buffer[0] = 0x00;
coap_pkt->buffer[0] |= COAP_HEADER_VERSION_MASK & coap_pkt->buffer[0] |= COAP_HEADER_VERSION_MASK &
(coap_pkt->version) << COAP_HEADER_VERSION_POSITION; (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_pkt->buffer[0] |=
COAP_HEADER_TYPE_MASK & (coap_pkt->type) << COAP_HEADER_TYPE_POSITION; COAP_HEADER_TOKEN_LEN_MASK & (coap_pkt->token_len)
coap_pkt->buffer[0] |= COAP_HEADER_TOKEN_LEN_MASK & << COAP_HEADER_TOKEN_LEN_POSITION;
(coap_pkt->token_len)
<< COAP_HEADER_TOKEN_LEN_POSITION;
coap_pkt->buffer[1] = coap_pkt->code; coap_pkt->buffer[1] = coap_pkt->code;
coap_pkt->buffer[2] = (uint8_t)((coap_pkt->mid) >> 8); coap_pkt->buffer[2] = (uint8_t)((coap_pkt->mid) >> 8);
coap_pkt->buffer[3] = (uint8_t)(coap_pkt->mid); coap_pkt->buffer[3] = (uint8_t)(coap_pkt->mid);
...@@ -1302,7 +1302,6 @@ coap_get_header_accept(void *packet, unsigned int *accept) ...@@ -1302,7 +1302,6 @@ coap_get_header_accept(void *packet, unsigned int *accept)
*accept = coap_pkt->accept; *accept = coap_pkt->accept;
return 1; return 1;
} }
#ifdef OC_CLIENT
int int
coap_set_header_accept(void *packet, unsigned int accept) coap_set_header_accept(void *packet, unsigned int accept)
{ {
...@@ -1312,7 +1311,6 @@ 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); SET_OPTION(coap_pkt, COAP_OPTION_ACCEPT);
return 1; return 1;
} }
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if 0 #if 0
int coap_get_header_max_age(void *packet, uint32_t *age) int coap_get_header_max_age(void *packet, uint32_t *age)
......
...@@ -316,15 +316,17 @@ coap_receive(oc_message_t *msg) ...@@ -316,15 +316,17 @@ coap_receive(oc_message_t *msg)
goto send_message; goto send_message;
} else { } else {
OC_DBG("received all blocks for payload"); OC_DBG("received all blocks for payload");
unsigned int cf = 0; if (message->type == COAP_TYPE_CON) {
int cf_was_set = coap_get_header_content_format(response, &cf); coap_send_empty_ack(message->mid, &msg->endpoint);
}
coap_udp_init_message(response, COAP_TYPE_CON, CONTENT_2_05, 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, coap_set_header_block1(response, block1_num, block1_more,
block1_size); block1_size);
if (cf_was_set) { coap_set_header_content_format(response,
coap_set_header_content_format(response, cf); APPLICATION_VND_OCF_CBOR);
} coap_set_header_accept(response, APPLICATION_VND_OCF_CBOR);
request_buffer->payload_size = request_buffer->payload_size =
request_buffer->next_block_offset; request_buffer->next_block_offset;
request_buffer->ref_count = 0; request_buffer->ref_count = 0;
...@@ -336,12 +338,6 @@ coap_receive(oc_message_t *msg) ...@@ -336,12 +338,6 @@ coap_receive(oc_message_t *msg)
goto init_reset_message; goto init_reset_message;
} else if (block2) { } else if (block2) {
OC_DBG("processing block2 option"); 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( response_buffer = oc_blockwise_find_response_buffer(
href, href_len, &msg->endpoint, message->code, message->uri_query, href, href_len, &msg->endpoint, message->code, message->uri_query,
message->uri_query_len, OC_BLOCKWISE_SERVER); message->uri_query_len, OC_BLOCKWISE_SERVER);
...@@ -364,14 +360,16 @@ coap_receive(oc_message_t *msg) ...@@ -364,14 +360,16 @@ coap_receive(oc_message_t *msg)
? 1 ? 1
: 0; : 0;
if (more == 0) { if (more == 0) {
unsigned int cf = 0; if (message->type == COAP_TYPE_CON) {
int cf_was_set = coap_get_header_content_format(response, &cf); coap_send_empty_ack(message->mid, &msg->endpoint);
coap_udp_init_message(response, COAP_TYPE_CON, CONTENT_2_05,
response->mid);
if (cf_was_set) {
coap_set_header_content_format(response, cf);
} }
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_payload(response, payload, payload_size);
coap_set_header_block2(response, block2_num, more, block2_size); coap_set_header_block2(response, block2_num, more, block2_size);
oc_blockwise_response_state_t *response_state = 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