Fixed CoAP format to be a uint16_t since the enum might compile to 8 bit and cause problems if 16-bit format types are used
This commit is contained in:
parent
1b0cdee9ec
commit
2351ee078a
|
@ -127,7 +127,7 @@ coap_set_option_header(unsigned int delta, size_t length, uint8_t *buffer)
|
|||
buffer[++written] = (length - 13);
|
||||
}
|
||||
|
||||
PRINTF("WRITTEN %u B opt header\n", 1 + written);
|
||||
PRINTF("WRITTEN %zu B opt header\n", 1 + written);
|
||||
|
||||
return ++written;
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ coap_serialize_int_option(unsigned int number, unsigned int current_number,
|
|||
if(0xFFFFFFFF & value) {
|
||||
++i;
|
||||
}
|
||||
PRINTF("OPTION %u (delta %u, len %u)\n", number, number - current_number,
|
||||
PRINTF("OPTION %u (delta %u, len %zu)\n", number, number - current_number,
|
||||
i);
|
||||
|
||||
i = coap_set_option_header(number - current_number, i, buffer);
|
||||
|
@ -177,8 +177,8 @@ coap_serialize_array_option(unsigned int number, unsigned int current_number,
|
|||
{
|
||||
size_t i = 0;
|
||||
|
||||
PRINTF("ARRAY type %u, len %u, full [%.*s]\n", number, length, length,
|
||||
array);
|
||||
PRINTF("ARRAY type %u, len %zu, full [%.*s]\n", number, length,
|
||||
(int)length, array);
|
||||
|
||||
if(split_char != '\0') {
|
||||
int j;
|
||||
|
@ -187,7 +187,7 @@ coap_serialize_array_option(unsigned int number, unsigned int current_number,
|
|||
size_t temp_length;
|
||||
|
||||
for(j = 0; j <= length + 1; ++j) {
|
||||
PRINTF("STEP %u/%u (%c)\n", j, length, array[j]);
|
||||
PRINTF("STEP %u/%zu (%c)\n", j, length, array[j]);
|
||||
if(array[j] == split_char || j == length) {
|
||||
part_end = array + j;
|
||||
temp_length = part_end - part_start;
|
||||
|
@ -197,8 +197,8 @@ coap_serialize_array_option(unsigned int number, unsigned int current_number,
|
|||
memcpy(&buffer[i], part_start, temp_length);
|
||||
i += temp_length;
|
||||
|
||||
PRINTF("OPTION type %u, delta %u, len %u, part [%.*s]\n", number,
|
||||
number - current_number, i, temp_length, part_start);
|
||||
PRINTF("OPTION type %u, delta %u, len %zu, part [%.*s]\n", number,
|
||||
number - current_number, i, (int)temp_length, part_start);
|
||||
|
||||
++j; /* skip the splitter */
|
||||
current_number = number;
|
||||
|
@ -210,7 +210,7 @@ coap_serialize_array_option(unsigned int number, unsigned int current_number,
|
|||
memcpy(&buffer[i], array, length);
|
||||
i += length;
|
||||
|
||||
PRINTF("OPTION type %u, delta %u, len %u\n", number,
|
||||
PRINTF("OPTION type %u, delta %u, len %zu\n", number,
|
||||
number - current_number, length);
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ coap_serialize_message(void *packet, uint8_t *buffer)
|
|||
|
||||
/* empty packet, dont need to do more stuff */
|
||||
if(!coap_pkt->code) {
|
||||
PRINTF("-Done serializing empty message at %p-\n", option);
|
||||
PRINTF("-Done serializing empty message at %p-\n", coap_pkt->buffer);
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
@ -370,6 +370,7 @@ coap_serialize_message(void *packet, uint8_t *buffer)
|
|||
"Location-Path");
|
||||
COAP_SERIALIZE_STRING_OPTION(COAP_OPTION_URI_PATH, uri_path, '/',
|
||||
"Uri-Path");
|
||||
PRINTF("Serialize content format: %d\n", coap_pkt->content_format);
|
||||
COAP_SERIALIZE_INT_OPTION(COAP_OPTION_CONTENT_FORMAT, content_format,
|
||||
"Content-Format");
|
||||
COAP_SERIALIZE_INT_OPTION(COAP_OPTION_MAX_AGE, max_age, "Max-Age");
|
||||
|
@ -405,8 +406,9 @@ coap_serialize_message(void *packet, uint8_t *buffer)
|
|||
}
|
||||
|
||||
PRINTF("-Done %u B (header len %u, payload len %u)-\n",
|
||||
coap_pkt->payload_len + option - buffer, option - buffer,
|
||||
coap_pkt->payload_len);
|
||||
(unsigned int)(coap_pkt->payload_len + option - buffer),
|
||||
(unsigned int)(option - buffer),
|
||||
(unsigned int)coap_pkt->payload_len);
|
||||
|
||||
PRINTF("Dump [0x%02X %02X %02X %02X %02X %02X %02X %02X]\n",
|
||||
coap_pkt->buffer[0],
|
||||
|
@ -540,7 +542,7 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
|
|||
case COAP_OPTION_MAX_AGE:
|
||||
coap_pkt->max_age = coap_parse_int_option(current_option,
|
||||
option_length);
|
||||
PRINTF("Max-Age [%lu]\n", coap_pkt->max_age);
|
||||
PRINTF("Max-Age [%lu]\n", (unsigned long)coap_pkt->max_age);
|
||||
break;
|
||||
case COAP_OPTION_ETAG:
|
||||
coap_pkt->etag_len = MIN(COAP_ETAG_LEN, option_length);
|
||||
|
@ -577,7 +579,7 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
|
|||
coap_pkt->proxy_uri = (char *)current_option;
|
||||
coap_pkt->proxy_uri_len = option_length;
|
||||
#endif
|
||||
PRINTF("Proxy-Uri NOT IMPLEMENTED [%.*s]\n", coap_pkt->proxy_uri_len,
|
||||
PRINTF("Proxy-Uri NOT IMPLEMENTED [%.*s]\n", (int)coap_pkt->proxy_uri_len,
|
||||
coap_pkt->proxy_uri);
|
||||
coap_error_message = "This is a constrained server (Contiki)";
|
||||
return PROXYING_NOT_SUPPORTED_5_05;
|
||||
|
@ -588,7 +590,7 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
|
|||
coap_pkt->proxy_scheme_len = option_length;
|
||||
#endif
|
||||
PRINTF("Proxy-Scheme NOT IMPLEMENTED [%.*s]\n",
|
||||
coap_pkt->proxy_scheme_len, coap_pkt->proxy_scheme);
|
||||
(int)coap_pkt->proxy_scheme_len, coap_pkt->proxy_scheme);
|
||||
coap_error_message = "This is a constrained server (Contiki)";
|
||||
return PROXYING_NOT_SUPPORTED_5_05;
|
||||
break;
|
||||
|
@ -596,7 +598,8 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
|
|||
case COAP_OPTION_URI_HOST:
|
||||
coap_pkt->uri_host = (char *)current_option;
|
||||
coap_pkt->uri_host_len = option_length;
|
||||
PRINTF("Uri-Host [%.*s]\n", coap_pkt->uri_host_len, coap_pkt->uri_host);
|
||||
PRINTF("Uri-Host [%.*s]\n", (int)coap_pkt->uri_host_len,
|
||||
coap_pkt->uri_host);
|
||||
break;
|
||||
case COAP_OPTION_URI_PORT:
|
||||
coap_pkt->uri_port = coap_parse_int_option(current_option,
|
||||
|
@ -608,14 +611,14 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
|
|||
coap_merge_multi_option((char **)&(coap_pkt->uri_path),
|
||||
&(coap_pkt->uri_path_len), current_option,
|
||||
option_length, '/');
|
||||
PRINTF("Uri-Path [%.*s]\n", coap_pkt->uri_path_len, coap_pkt->uri_path);
|
||||
PRINTF("Uri-Path [%.*s]\n", (int)coap_pkt->uri_path_len, coap_pkt->uri_path);
|
||||
break;
|
||||
case COAP_OPTION_URI_QUERY:
|
||||
/* coap_merge_multi_option() operates in-place on the IPBUF, but final packet field should be const string -> cast to string */
|
||||
coap_merge_multi_option((char **)&(coap_pkt->uri_query),
|
||||
&(coap_pkt->uri_query_len), current_option,
|
||||
option_length, '&');
|
||||
PRINTF("Uri-Query [%.*s]\n", coap_pkt->uri_query_len,
|
||||
PRINTF("Uri-Query [%.*s]\n", (int)coap_pkt->uri_query_len,
|
||||
coap_pkt->uri_query);
|
||||
break;
|
||||
|
||||
|
@ -624,7 +627,7 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
|
|||
coap_merge_multi_option((char **)&(coap_pkt->location_path),
|
||||
&(coap_pkt->location_path_len), current_option,
|
||||
option_length, '/');
|
||||
PRINTF("Location-Path [%.*s]\n", coap_pkt->location_path_len,
|
||||
PRINTF("Location-Path [%.*s]\n", (int)coap_pkt->location_path_len,
|
||||
coap_pkt->location_path);
|
||||
break;
|
||||
case COAP_OPTION_LOCATION_QUERY:
|
||||
|
@ -632,14 +635,14 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
|
|||
coap_merge_multi_option((char **)&(coap_pkt->location_query),
|
||||
&(coap_pkt->location_query_len), current_option,
|
||||
option_length, '&');
|
||||
PRINTF("Location-Query [%.*s]\n", coap_pkt->location_query_len,
|
||||
PRINTF("Location-Query [%.*s]\n", (int)coap_pkt->location_query_len,
|
||||
coap_pkt->location_query);
|
||||
break;
|
||||
|
||||
case COAP_OPTION_OBSERVE:
|
||||
coap_pkt->observe = coap_parse_int_option(current_option,
|
||||
option_length);
|
||||
PRINTF("Observe [%lu]\n", coap_pkt->observe);
|
||||
PRINTF("Observe [%lu]\n", (unsigned long)coap_pkt->observe);
|
||||
break;
|
||||
case COAP_OPTION_BLOCK2:
|
||||
coap_pkt->block2_num = coap_parse_int_option(current_option,
|
||||
|
@ -649,7 +652,8 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
|
|||
coap_pkt->block2_offset = (coap_pkt->block2_num & ~0x0000000F)
|
||||
<< (coap_pkt->block2_num & 0x07);
|
||||
coap_pkt->block2_num >>= 4;
|
||||
PRINTF("Block2 [%lu%s (%u B/blk)]\n", coap_pkt->block2_num,
|
||||
PRINTF("Block2 [%lu%s (%u B/blk)]\n",
|
||||
(unsigned long)coap_pkt->block2_num,
|
||||
coap_pkt->block2_more ? "+" : "", coap_pkt->block2_size);
|
||||
break;
|
||||
case COAP_OPTION_BLOCK1:
|
||||
|
@ -660,16 +664,17 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
|
|||
coap_pkt->block1_offset = (coap_pkt->block1_num & ~0x0000000F)
|
||||
<< (coap_pkt->block1_num & 0x07);
|
||||
coap_pkt->block1_num >>= 4;
|
||||
PRINTF("Block1 [%lu%s (%u B/blk)]\n", coap_pkt->block1_num,
|
||||
PRINTF("Block1 [%lu%s (%u B/blk)]\n",
|
||||
(unsigned long)coap_pkt->block1_num,
|
||||
coap_pkt->block1_more ? "+" : "", coap_pkt->block1_size);
|
||||
break;
|
||||
case COAP_OPTION_SIZE2:
|
||||
coap_pkt->size2 = coap_parse_int_option(current_option, option_length);
|
||||
PRINTF("Size2 [%lu]\n", coap_pkt->size2);
|
||||
PRINTF("Size2 [%lu]\n", (unsigned long)coap_pkt->size2);
|
||||
break;
|
||||
case COAP_OPTION_SIZE1:
|
||||
coap_pkt->size1 = coap_parse_int_option(current_option, option_length);
|
||||
PRINTF("Size1 [%lu]\n", coap_pkt->size1);
|
||||
PRINTF("Size1 [%lu]\n", (unsigned long)coap_pkt->size1);
|
||||
break;
|
||||
default:
|
||||
PRINTF("unknown (%u)\n", option_number);
|
||||
|
@ -752,7 +757,7 @@ coap_set_header_content_format(void *packet, unsigned int format)
|
|||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
coap_pkt->content_format = (coap_content_format_t)format;
|
||||
coap_pkt->content_format = format;
|
||||
SET_OPTION(coap_pkt, COAP_OPTION_CONTENT_FORMAT);
|
||||
return 1;
|
||||
}
|
||||
|
@ -773,7 +778,7 @@ coap_set_header_accept(void *packet, unsigned int accept)
|
|||
{
|
||||
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
|
||||
|
||||
coap_pkt->accept = (coap_content_format_t)accept;
|
||||
coap_pkt->accept = accept;
|
||||
SET_OPTION(coap_pkt, COAP_OPTION_ACCEPT);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ typedef struct {
|
|||
|
||||
uint8_t options[COAP_OPTION_SIZE1 / OPTION_MAP_SIZE + 1]; /* bitmap to check if option is set */
|
||||
|
||||
coap_content_format_t content_format; /* parse options once and store; allows setting options in random order */
|
||||
uint16_t content_format; /* parse options once and store; allows setting options in random order */
|
||||
uint32_t max_age;
|
||||
uint8_t etag_len;
|
||||
uint8_t etag[COAP_ETAG_LEN];
|
||||
|
@ -111,7 +111,7 @@ typedef struct {
|
|||
size_t uri_path_len;
|
||||
const char *uri_path;
|
||||
int32_t observe;
|
||||
coap_content_format_t accept;
|
||||
uint16_t accept;
|
||||
uint8_t if_match_len;
|
||||
uint8_t if_match[COAP_ETAG_LEN];
|
||||
uint32_t block2_num;
|
||||
|
@ -135,13 +135,13 @@ typedef struct {
|
|||
/* option format serialization */
|
||||
#define COAP_SERIALIZE_INT_OPTION(number, field, text) \
|
||||
if(IS_OPTION(coap_pkt, number)) { \
|
||||
PRINTF(text " [%u]\n", coap_pkt->field); \
|
||||
PRINTF(text " [%u]\n", (unsigned int)coap_pkt->field); \
|
||||
option += coap_serialize_int_option(number, current_number, option, coap_pkt->field); \
|
||||
current_number = number; \
|
||||
}
|
||||
#define COAP_SERIALIZE_BYTE_OPTION(number, field, text) \
|
||||
if(IS_OPTION(coap_pkt, number)) { \
|
||||
PRINTF(text " %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", coap_pkt->field##_len, \
|
||||
PRINTF(text " %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", (unsigned int)coap_pkt->field##_len, \
|
||||
coap_pkt->field[0], \
|
||||
coap_pkt->field[1], \
|
||||
coap_pkt->field[2], \
|
||||
|
@ -156,18 +156,18 @@ typedef struct {
|
|||
}
|
||||
#define COAP_SERIALIZE_STRING_OPTION(number, field, splitter, text) \
|
||||
if(IS_OPTION(coap_pkt, number)) { \
|
||||
PRINTF(text " [%.*s]\n", coap_pkt->field##_len, coap_pkt->field); \
|
||||
PRINTF(text " [%.*s]\n", (int)coap_pkt->field##_len, coap_pkt->field); \
|
||||
option += coap_serialize_array_option(number, current_number, option, (uint8_t *)coap_pkt->field, coap_pkt->field##_len, splitter); \
|
||||
current_number = number; \
|
||||
}
|
||||
#define COAP_SERIALIZE_BLOCK_OPTION(number, field, text) \
|
||||
if(IS_OPTION(coap_pkt, number)) \
|
||||
{ \
|
||||
PRINTF(text " [%lu%s (%u B/blk)]\n", coap_pkt->field##_num, coap_pkt->field##_more ? "+" : "", coap_pkt->field##_size); \
|
||||
PRINTF(text " [%lu%s (%u B/blk)]\n", (unsigned long)coap_pkt->field##_num, coap_pkt->field##_more ? "+" : "", coap_pkt->field##_size); \
|
||||
uint32_t block = coap_pkt->field##_num << 4; \
|
||||
if(coap_pkt->field##_more) { block |= 0x8; } \
|
||||
block |= 0xF & coap_log_2(coap_pkt->field##_size / 16); \
|
||||
PRINTF(text " encoded: 0x%lX\n", block); \
|
||||
PRINTF(text " encoded: 0x%lX\n", (unsigned long)block); \
|
||||
option += coap_serialize_int_option(number, current_number, option, block); \
|
||||
current_number = number; \
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue