Fixed option header bug for large deltas.
This commit is contained in:
parent
af93e5fbd9
commit
56f877b633
@ -90,7 +90,7 @@ coap_parse_int_option(uint8_t *bytes, size_t length)
|
|||||||
while (i<length)
|
while (i<length)
|
||||||
{
|
{
|
||||||
var <<= 8;
|
var <<= 8;
|
||||||
var |= 0xFF & bytes[i++];
|
var |= bytes[i++];
|
||||||
}
|
}
|
||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ static
|
|||||||
size_t
|
size_t
|
||||||
coap_set_option_header(unsigned int delta, size_t length, uint8_t *buffer)
|
coap_set_option_header(unsigned int delta, size_t length, uint8_t *buffer)
|
||||||
{
|
{
|
||||||
size_t written = 1;
|
size_t written = 0;
|
||||||
|
|
||||||
buffer[0] = coap_option_nibble(delta)<<4 | coap_option_nibble(length);
|
buffer[0] = coap_option_nibble(delta)<<4 | coap_option_nibble(length);
|
||||||
|
|
||||||
@ -127,19 +127,19 @@ coap_set_option_header(unsigned int delta, size_t length, uint8_t *buffer)
|
|||||||
{
|
{
|
||||||
if (*x>268)
|
if (*x>268)
|
||||||
{
|
{
|
||||||
buffer[written++] = (*x-269)>>8;
|
buffer[++written] = (*x-269)>>8;
|
||||||
buffer[written++] = (*x-269);
|
buffer[++written] = (*x-269);
|
||||||
}
|
}
|
||||||
else if (delta>12)
|
else if (*x>12)
|
||||||
{
|
{
|
||||||
buffer[written++] = (*x-13);
|
buffer[++written] = (*x-13);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (x!=&length && (x=&length));
|
while (x!=&length && (x=&length));
|
||||||
|
|
||||||
PRINTF("WRITTEN %u B opt header\n", written);
|
PRINTF("WRITTEN %u B opt header\n", written);
|
||||||
|
|
||||||
return written;
|
return ++written;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
static
|
static
|
||||||
@ -148,14 +148,19 @@ coap_serialize_int_option(unsigned int number, unsigned int current_number, uint
|
|||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
if (0xFF000000 & value) buffer[++i] = (uint8_t) (0xFF & value>>24);
|
if (0xFF000000 & value) ++i;
|
||||||
if (0xFFFF0000 & value) buffer[++i] = (uint8_t) (0xFF & value>>16);
|
if (0xFFFF0000 & value) ++i;
|
||||||
if (0xFFFFFF00 & value) buffer[++i] = (uint8_t) (0xFF & value>>8);
|
if (0xFFFFFF00 & value) ++i;
|
||||||
if (0xFFFFFFFF & value) buffer[++i] = (uint8_t) (0xFF & value);
|
if (0xFFFFFFFF & value) ++i;
|
||||||
|
|
||||||
PRINTF("OPTION %u (delta %u, len %u)\n", number, number - current_number, i);
|
PRINTF("OPTION %u (delta %u, len %u)\n", number, number - current_number, i);
|
||||||
|
|
||||||
i += coap_set_option_header(number - current_number, i, buffer);
|
i = coap_set_option_header(number - current_number, i, buffer);
|
||||||
|
|
||||||
|
if (0xFF000000 & value) buffer[i++] = (uint8_t) (value>>24);
|
||||||
|
if (0xFFFF0000 & value) buffer[i++] = (uint8_t) (value>>16);
|
||||||
|
if (0xFFFFFF00 & value) buffer[i++] = (uint8_t) (value>>8);
|
||||||
|
if (0xFFFFFFFF & value) buffer[i++] = (uint8_t) (value);
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@ -319,8 +324,8 @@ coap_serialize_message(void *packet, uint8_t *buffer)
|
|||||||
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_POSITION;
|
coap_pkt->buffer[0] |= COAP_HEADER_TOKEN_LEN_MASK & (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] = 0xFF & (coap_pkt->mid)>>8;
|
coap_pkt->buffer[2] = (uint8_t) ((coap_pkt->mid)>>8);
|
||||||
coap_pkt->buffer[3] = 0xFF & coap_pkt->mid;
|
coap_pkt->buffer[3] = (uint8_t) (coap_pkt->mid);
|
||||||
|
|
||||||
/* set Token */
|
/* set Token */
|
||||||
PRINTF("Token (len %u)", coap_pkt->token_len);
|
PRINTF("Token (len %u)", coap_pkt->token_len);
|
||||||
|
Loading…
Reference in New Issue
Block a user