mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #11270 from anttiylitokola/update-mbed-coap-to-4.8.1
Update mbed-coap to version 4.8.1pull/11289/head
commit
6812869ad5
|
@ -1,5 +1,14 @@
|
|||
# Change Log
|
||||
|
||||
## [v4.8.1(https://github.com/ARMmbed/mbed-coap/releases/tag/v4.8.1)
|
||||
- Store ACK's also into duplicate info list.
|
||||
- ROM size optimization. Flash size has gone down ~1100 bytes.
|
||||
|
||||
**Closed issues:**
|
||||
- IOTCLT-3592 - Client does not handle Duplicate ACK messages during blockwise registration correctly
|
||||
|
||||
-[Full Changelog](https://github.com/ARMmbed/mbed-coap/compare/v4.8.0...v4.8.1)
|
||||
|
||||
## [v4.8.0](https://github.com/ARMmbed/mbed-coap/releases/tag/v4.8.0)
|
||||
- Make `sn_coap_protocol_linked_list_duplication_info_remove` API to public. User might want to delete some messages from the duplicate list.
|
||||
- Enable support for unified client configuration.
|
||||
|
|
|
@ -49,7 +49,7 @@ test: $(TESTDIRS)
|
|||
@rm -f lcov/index.xml
|
||||
@find ./ -name '*.gcno' | xargs cp --backup=numbered -t ./coverage/
|
||||
@find ./ -name '*.gcda' | xargs cp --backup=numbered -t ./coverage/
|
||||
@gcovr --object-directory ./coverage --exclude-unreachable-branches -e '.*/builds/.*' -e '.*/test/.*' -e '.*/stubs/.*' -e '.*/mbed-coap/.*' -x -o ./lcov/gcovr.xml
|
||||
@gcovr --object-directory ./coverage --exclude-unreachable-branches -e '.*/builds/.*' -e '.*/CppUTest/.*' -e '.*/mbed-client-libservice/.*' -e '.*/test/.*' -e '.*/stubs/.*' -e '.*/mbed-coap/.*' -x -o ./lcov/gcovr.xml
|
||||
@lcov -d test/. -c -o $(COVERAGEFILE)
|
||||
@lcov -q -r $(COVERAGEFILE) "/usr*" -o $(COVERAGEFILE)
|
||||
@lcov -q -r $(COVERAGEFILE) "/test*" -o $(COVERAGEFILE)
|
||||
|
|
|
@ -338,7 +338,7 @@ extern void sn_coap_parser_release_allocated_coap_msg_mem(struct coap_s *handle,
|
|||
* -1 = Failure in given CoAP header structure\n
|
||||
* -2 = Failure in given pointer (= NULL)
|
||||
*/
|
||||
extern int16_t sn_coap_builder(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr);
|
||||
extern int16_t sn_coap_builder(uint8_t *dst_packet_data_ptr, const sn_coap_hdr_s *src_coap_msg_ptr);
|
||||
|
||||
/**
|
||||
* \fn uint16_t sn_coap_builder_calc_needed_packet_data_size(sn_coap_hdr_s *src_coap_msg_ptr)
|
||||
|
@ -351,7 +351,7 @@ extern int16_t sn_coap_builder(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_
|
|||
* \return Return value is count of needed memory as bytes for build Packet data
|
||||
* Null if failed
|
||||
*/
|
||||
extern uint16_t sn_coap_builder_calc_needed_packet_data_size(sn_coap_hdr_s *src_coap_msg_ptr);
|
||||
extern uint16_t sn_coap_builder_calc_needed_packet_data_size(const sn_coap_hdr_s *src_coap_msg_ptr);
|
||||
|
||||
/**
|
||||
* \fn int16_t sn_coap_builder_2(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_size)
|
||||
|
@ -368,7 +368,7 @@ extern uint16_t sn_coap_builder_calc_needed_packet_data_size(sn_coap_hdr_s *src_
|
|||
* -1 = Failure in given CoAP header structure\n
|
||||
* -2 = Failure in given pointer (= NULL)
|
||||
*/
|
||||
extern int16_t sn_coap_builder_2(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_payload_size);
|
||||
extern int16_t sn_coap_builder_2(uint8_t *dst_packet_data_ptr, const sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_payload_size);
|
||||
|
||||
/**
|
||||
* \fn uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_payload_size)
|
||||
|
@ -382,7 +382,7 @@ extern int16_t sn_coap_builder_2(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *sr
|
|||
* \return Return value is count of needed memory as bytes for build Packet data
|
||||
* Null if failed
|
||||
*/
|
||||
extern uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_payload_size);
|
||||
extern uint16_t sn_coap_builder_calc_needed_packet_data_size_2(const sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_payload_size);
|
||||
|
||||
/**
|
||||
* \fn sn_coap_hdr_s *sn_coap_build_response(struct coap_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code)
|
||||
|
@ -397,7 +397,7 @@ extern uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *sr
|
|||
* NULL Error in parsing the request
|
||||
*
|
||||
*/
|
||||
extern sn_coap_hdr_s *sn_coap_build_response(struct coap_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code);
|
||||
extern sn_coap_hdr_s *sn_coap_build_response(struct coap_s *handle, const sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code);
|
||||
|
||||
/**
|
||||
* \brief Initialise a message structure to empty
|
||||
|
@ -436,6 +436,8 @@ extern sn_coap_hdr_s *sn_coap_parser_alloc_message(struct coap_s *handle);
|
|||
*/
|
||||
extern sn_coap_options_list_s *sn_coap_parser_alloc_options(struct coap_s *handle, sn_coap_hdr_s *coap_msg_ptr);
|
||||
|
||||
extern sn_coap_hdr_s *sn_coap_parser_alloc_message_with_options(struct coap_s *handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -38,7 +38,8 @@ extern "C" {
|
|||
*
|
||||
* \param *used_malloc_func_ptr is function pointer for used memory allocation function.
|
||||
*
|
||||
* \param *used_free_func_ptr is function pointer for used memory free function.
|
||||
* \param *used_free_func_ptr is function pointer for used memory free function. Note: the implementation
|
||||
* must handle NULL parameter and ignore it just as typical libc's free() does.
|
||||
*
|
||||
* \param *used_tx_callback_ptr function callback pointer to tx function for sending coap messages
|
||||
*
|
||||
|
@ -234,7 +235,7 @@ extern int8_t sn_coap_protocol_delete_retransmission(struct coap_s *handle, uint
|
|||
*
|
||||
* \brief If re-transmissions are enabled, this function removes message from retransmission buffer.
|
||||
*/
|
||||
extern int8_t sn_coap_protocol_delete_retransmission_by_token(struct coap_s *handle, uint8_t *token, uint8_t token_len);
|
||||
extern int8_t sn_coap_protocol_delete_retransmission_by_token(struct coap_s *handle, const uint8_t *token, uint8_t token_len);
|
||||
|
||||
/**
|
||||
* \fn int8_t sn_coap_convert_block_size(uint16_t block_size)
|
||||
|
|
|
@ -250,4 +250,14 @@
|
|||
#define SN_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE UINT16_MAX
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def SN_COAP_BLOCKWISE_INTERNAL_BLOCK_2_HANDLING_ENABLED
|
||||
* \brief A size optimization switch, which removes the blockwise Block2 response if set to 0.
|
||||
* handling code which is typically overridden by a call of "sn_coap_protocol_handle_block2_response_internally(coap, false);".
|
||||
* By default the code is there, so the override can be reversed by "sn_coap_protocol_handle_block2_response_internally(coap, true)".
|
||||
*/
|
||||
#ifndef SN_COAP_BLOCKWISE_INTERNAL_BLOCK_2_HANDLING_ENABLED
|
||||
#define SN_COAP_BLOCKWISE_INTERNAL_BLOCK_2_HANDLING_ENABLED 1
|
||||
#endif
|
||||
|
||||
#endif // SN_CONFIG_H
|
||||
|
|
|
@ -58,7 +58,7 @@ extern "C" {
|
|||
* \brief This structure is returned by sn_coap_exec() for sending
|
||||
*/
|
||||
typedef struct sn_nsdl_transmit_ {
|
||||
sn_nsdl_addr_s *dst_addr_ptr;
|
||||
sn_nsdl_addr_s dst_addr_ptr;
|
||||
|
||||
sn_nsdl_capab_e protocol;
|
||||
|
||||
|
@ -69,7 +69,7 @@ typedef struct sn_nsdl_transmit_ {
|
|||
/* * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* * * * EXTERNAL FUNCTION PROTOTYPES * * * */
|
||||
/* * * * * * * * * * * * * * * * * * * * * * */
|
||||
extern int8_t sn_coap_header_validity_check(sn_coap_hdr_s *src_coap_msg_ptr, coap_version_e coap_version);
|
||||
extern int8_t sn_coap_header_validity_check(const sn_coap_hdr_s *src_coap_msg_ptr, coap_version_e coap_version);
|
||||
|
||||
#endif /* SN_COAP_HEADER_INTERNAL_H_ */
|
||||
|
||||
|
|
|
@ -48,9 +48,8 @@ typedef struct coap_send_msg_ {
|
|||
uint8_t resending_counter; /* Tells how many times message is still tried to resend */
|
||||
uint32_t resending_time; /* Tells next resending time */
|
||||
|
||||
sn_nsdl_transmit_s *send_msg_ptr;
|
||||
sn_nsdl_transmit_s send_msg_ptr;
|
||||
|
||||
struct coap_s *coap; /* CoAP library handle */
|
||||
void *param; /* Extra parameter that will be passed to TX/RX callback functions */
|
||||
|
||||
ns_list_link_t link;
|
||||
|
@ -64,7 +63,6 @@ typedef struct coap_duplication_info_ {
|
|||
uint16_t msg_id;
|
||||
uint16_t packet_len;
|
||||
uint8_t *packet_ptr;
|
||||
struct coap_s *coap; /* CoAP library handle */
|
||||
sn_nsdl_addr_s *address;
|
||||
void *param;
|
||||
ns_list_link_t link;
|
||||
|
@ -77,7 +75,6 @@ typedef struct coap_blockwise_msg_ {
|
|||
uint32_t timestamp; /* Tells when Blockwise message is stored to Linked list */
|
||||
|
||||
sn_coap_hdr_s *coap_msg_ptr;
|
||||
struct coap_s *coap; /* CoAP library handle */
|
||||
|
||||
void *param;
|
||||
uint16_t msg_id;
|
||||
|
@ -100,7 +97,6 @@ typedef struct coap_blockwise_payload_ {
|
|||
|
||||
uint16_t payload_len;
|
||||
uint8_t *payload_ptr;
|
||||
struct coap_s *coap; /* CoAP library handle */
|
||||
|
||||
ns_list_link_t link;
|
||||
} coap_blockwise_payload_s;
|
||||
|
@ -139,6 +135,12 @@ struct coap_s {
|
|||
uint8_t sn_coap_internal_block2_resp_handling; /* If this is set then coap itself sends a next GET request automatically */
|
||||
};
|
||||
|
||||
/* Utility function which performs a call to sn_coap_protocol_malloc() and memset's the result to zero. */
|
||||
void *sn_coap_protocol_calloc(struct coap_s *handle, uint16_t length);
|
||||
|
||||
/* Utility function which performs a call to sn_coap_protocol_malloc() and memcopy's the source to result buffer. */
|
||||
void *sn_coap_protocol_malloc_copy(struct coap_s *handle, const void *source, uint16_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -37,19 +37,19 @@
|
|||
|
||||
#define TRACE_GROUP "coap"
|
||||
/* * * * LOCAL FUNCTION PROTOTYPES * * * */
|
||||
static int8_t sn_coap_builder_header_build(uint8_t **dst_packet_data_pptr, sn_coap_hdr_s *src_coap_msg_ptr);
|
||||
static int8_t sn_coap_builder_options_build(uint8_t **dst_packet_data_pptr, sn_coap_hdr_s *src_coap_msg_ptr);
|
||||
static uint16_t sn_coap_builder_options_calc_option_size(uint16_t query_len, uint8_t *query_ptr, sn_coap_option_numbers_e option);
|
||||
static int16_t sn_coap_builder_options_build_add_one_option(uint8_t **dst_packet_data_pptr, uint16_t option_len, uint8_t *option_ptr, sn_coap_option_numbers_e option_number, uint16_t *previous_option_number);
|
||||
static int16_t sn_coap_builder_options_build_add_multiple_option(uint8_t **dst_packet_data_pptr, uint8_t **src_pptr, uint16_t *src_len_ptr, sn_coap_option_numbers_e option, uint16_t *previous_option_number);
|
||||
static int8_t sn_coap_builder_header_build(uint8_t **dst_packet_data_pptr, const sn_coap_hdr_s *src_coap_msg_ptr);
|
||||
static int8_t sn_coap_builder_options_build(uint8_t **dst_packet_data_pptr, const sn_coap_hdr_s *src_coap_msg_ptr);
|
||||
static uint16_t sn_coap_builder_options_calc_option_size(uint16_t query_len, const uint8_t *query_ptr, sn_coap_option_numbers_e option);
|
||||
static int16_t sn_coap_builder_options_build_add_one_option(uint8_t **dst_packet_data_pptr, uint16_t option_len, const uint8_t *option_ptr, sn_coap_option_numbers_e option_number, uint16_t *previous_option_number);
|
||||
static void sn_coap_builder_options_build_add_multiple_option(uint8_t **dst_packet_data_pptr, const uint8_t *src_pptr, uint16_t src_len_ptr, sn_coap_option_numbers_e option, uint16_t *previous_option_number);
|
||||
static uint8_t sn_coap_builder_options_build_add_uint_option(uint8_t **dst_packet_data_pptr, uint32_t value, sn_coap_option_numbers_e option_number, uint16_t *previous_option_number);
|
||||
static uint8_t sn_coap_builder_options_get_option_part_count(uint16_t query_len, uint8_t *query_ptr, sn_coap_option_numbers_e option);
|
||||
static uint16_t sn_coap_builder_options_get_option_part_length_from_whole_option_string(uint16_t query_len, uint8_t *query_ptr, uint8_t query_index, sn_coap_option_numbers_e option);
|
||||
static int16_t sn_coap_builder_options_get_option_part_position(uint16_t query_len, uint8_t *query_ptr, uint8_t query_index, sn_coap_option_numbers_e option);
|
||||
static void sn_coap_builder_payload_build(uint8_t **dst_packet_data_pptr, sn_coap_hdr_s *src_coap_msg_ptr);
|
||||
static uint8_t sn_coap_builder_options_calculate_jump_need(sn_coap_hdr_s *src_coap_msg_ptr/*, uint8_t block_option*/);
|
||||
static uint8_t sn_coap_builder_options_get_option_part_count(uint16_t query_len, const uint8_t *query_ptr, sn_coap_option_numbers_e option);
|
||||
static uint16_t sn_coap_builder_options_get_option_part_length_from_whole_option_string(uint16_t query_len, const uint8_t *query_ptr, uint8_t query_index, sn_coap_option_numbers_e option);
|
||||
static int16_t sn_coap_builder_options_get_option_part_position(uint16_t query_len, const uint8_t *query_ptr, uint8_t query_index, sn_coap_option_numbers_e option);
|
||||
static void sn_coap_builder_payload_build(uint8_t **dst_packet_data_pptr, const sn_coap_hdr_s *src_coap_msg_ptr);
|
||||
static uint8_t sn_coap_builder_options_calculate_jump_need(const sn_coap_hdr_s *src_coap_msg_ptr);
|
||||
|
||||
sn_coap_hdr_s *sn_coap_build_response(struct coap_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code)
|
||||
sn_coap_hdr_s *sn_coap_build_response(struct coap_s *handle, const sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code)
|
||||
{
|
||||
sn_coap_hdr_s *coap_res_ptr;
|
||||
|
||||
|
@ -86,25 +86,24 @@ sn_coap_hdr_s *sn_coap_build_response(struct coap_s *handle, sn_coap_hdr_s *coap
|
|||
|
||||
if (coap_packet_ptr->token_ptr) {
|
||||
coap_res_ptr->token_len = coap_packet_ptr->token_len;
|
||||
coap_res_ptr->token_ptr = handle->sn_coap_protocol_malloc(coap_res_ptr->token_len);
|
||||
coap_res_ptr->token_ptr = sn_coap_protocol_malloc_copy(handle, coap_packet_ptr->token_ptr, coap_res_ptr->token_len);
|
||||
if (!coap_res_ptr->token_ptr) {
|
||||
tr_error("sn_coap_build_response - failed to allocate token!");
|
||||
handle->sn_coap_protocol_free(coap_res_ptr);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(coap_res_ptr->token_ptr, coap_packet_ptr->token_ptr, coap_res_ptr->token_len);
|
||||
}
|
||||
return coap_res_ptr;
|
||||
}
|
||||
|
||||
int16_t sn_coap_builder(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr)
|
||||
int16_t sn_coap_builder(uint8_t *dst_packet_data_ptr, const sn_coap_hdr_s *src_coap_msg_ptr)
|
||||
{
|
||||
return sn_coap_builder_2(dst_packet_data_ptr, src_coap_msg_ptr, SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE);
|
||||
}
|
||||
|
||||
int16_t sn_coap_builder_2(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_payload_size)
|
||||
int16_t sn_coap_builder_2(uint8_t *dst_packet_data_ptr, const sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_payload_size)
|
||||
{
|
||||
uint8_t *base_packet_data_ptr = NULL;
|
||||
uint8_t *base_packet_data_ptr;
|
||||
|
||||
/* * * * Check given pointers * * * */
|
||||
if (dst_packet_data_ptr == NULL || src_coap_msg_ptr == NULL) {
|
||||
|
@ -118,6 +117,7 @@ int16_t sn_coap_builder_2(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_
|
|||
return -1;
|
||||
}
|
||||
|
||||
// XXX: this should not be needed anymore but I have no courage to remove it yet.
|
||||
memset(dst_packet_data_ptr, 0, dst_byte_count_to_be_built);
|
||||
|
||||
/* * * * Store base (= original) destination Packet data pointer for later usage * * * */
|
||||
|
@ -147,12 +147,12 @@ int16_t sn_coap_builder_2(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_
|
|||
/* * * * Return built Packet data length * * * */
|
||||
return (dst_packet_data_ptr - base_packet_data_ptr);
|
||||
}
|
||||
uint16_t sn_coap_builder_calc_needed_packet_data_size(sn_coap_hdr_s *src_coap_msg_ptr)
|
||||
uint16_t sn_coap_builder_calc_needed_packet_data_size(const sn_coap_hdr_s *src_coap_msg_ptr)
|
||||
{
|
||||
return sn_coap_builder_calc_needed_packet_data_size_2(src_coap_msg_ptr, SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE);
|
||||
}
|
||||
|
||||
uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_payload_size)
|
||||
uint16_t sn_coap_builder_calc_needed_packet_data_size_2(const sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_payload_size)
|
||||
{
|
||||
(void)blockwise_payload_size;
|
||||
uint16_t returned_byte_count = 0;
|
||||
|
@ -203,30 +203,33 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_
|
|||
}
|
||||
/* If options list pointer exists */
|
||||
if (src_coap_msg_ptr->options_list_ptr != NULL) {
|
||||
|
||||
const sn_coap_options_list_s *src_options_list_ptr = src_coap_msg_ptr->options_list_ptr;
|
||||
|
||||
/* ACCEPT - An integer option, up to 2 bytes */
|
||||
if (src_coap_msg_ptr->options_list_ptr->accept != COAP_CT_NONE) {
|
||||
if ((uint32_t) src_coap_msg_ptr->options_list_ptr->accept > 0xffff) {
|
||||
if (src_options_list_ptr->accept != COAP_CT_NONE) {
|
||||
if ((uint32_t) src_options_list_ptr->accept > 0xffff) {
|
||||
tr_error("sn_coap_builder_calc_needed_packet_data_size_2 - accept too large!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_coap_msg_ptr->options_list_ptr->accept, COAP_OPTION_ACCEPT, &tempInt);
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_options_list_ptr->accept, COAP_OPTION_ACCEPT, &tempInt);
|
||||
}
|
||||
/* MAX AGE - An integer option, omitted for default. Up to 4 bytes */
|
||||
if (src_coap_msg_ptr->options_list_ptr->max_age != COAP_OPTION_MAX_AGE_DEFAULT) {
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_coap_msg_ptr->options_list_ptr->max_age, COAP_OPTION_MAX_AGE, &tempInt);
|
||||
if (src_options_list_ptr->max_age != COAP_OPTION_MAX_AGE_DEFAULT) {
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_options_list_ptr->max_age, COAP_OPTION_MAX_AGE, &tempInt);
|
||||
}
|
||||
/* PROXY URI - Length of this option is 1-1034 bytes */
|
||||
if (src_coap_msg_ptr->options_list_ptr->proxy_uri_ptr != NULL) {
|
||||
if (src_coap_msg_ptr->options_list_ptr->proxy_uri_len >= 1 && src_coap_msg_ptr->options_list_ptr->proxy_uri_len <= 12) { /* Add option header byte(s) - depending of option length */
|
||||
if (src_options_list_ptr->proxy_uri_ptr != NULL) {
|
||||
if (src_options_list_ptr->proxy_uri_len >= 1 && src_options_list_ptr->proxy_uri_len <= 12) { /* Add option header byte(s) - depending of option length */
|
||||
returned_byte_count++;
|
||||
}
|
||||
|
||||
else if (src_coap_msg_ptr->options_list_ptr->proxy_uri_len >= 13 && src_coap_msg_ptr->options_list_ptr->proxy_uri_len <= 269) {
|
||||
else if (src_options_list_ptr->proxy_uri_len >= 13 && src_options_list_ptr->proxy_uri_len <= 269) {
|
||||
returned_byte_count += 2;
|
||||
}
|
||||
|
||||
else if (src_coap_msg_ptr->options_list_ptr->proxy_uri_len >= 270 && src_coap_msg_ptr->options_list_ptr->proxy_uri_len <= 1034) {
|
||||
else if (src_options_list_ptr->proxy_uri_len >= 270 && src_options_list_ptr->proxy_uri_len <= 1034) {
|
||||
returned_byte_count += 3;
|
||||
}
|
||||
|
||||
|
@ -236,12 +239,12 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_
|
|||
}
|
||||
|
||||
/* Add needed memory for Option value */
|
||||
returned_byte_count += src_coap_msg_ptr->options_list_ptr->proxy_uri_len;
|
||||
returned_byte_count += src_options_list_ptr->proxy_uri_len;
|
||||
}
|
||||
/* ETAG - Repeatable option. Length of this option is 1-8 bytes*/
|
||||
if (src_coap_msg_ptr->options_list_ptr->etag_ptr != NULL) {
|
||||
repeatable_option_size = sn_coap_builder_options_calc_option_size(src_coap_msg_ptr->options_list_ptr->etag_len,
|
||||
src_coap_msg_ptr->options_list_ptr->etag_ptr, COAP_OPTION_ETAG);
|
||||
if (src_options_list_ptr->etag_ptr != NULL) {
|
||||
repeatable_option_size = sn_coap_builder_options_calc_option_size(src_options_list_ptr->etag_len,
|
||||
src_options_list_ptr->etag_ptr, COAP_OPTION_ETAG);
|
||||
if (repeatable_option_size) {
|
||||
returned_byte_count += repeatable_option_size;
|
||||
} else {
|
||||
|
@ -250,12 +253,12 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_
|
|||
}
|
||||
}
|
||||
/* URI HOST - Length of this option is 1-255 bytes */
|
||||
if (src_coap_msg_ptr->options_list_ptr->uri_host_ptr != NULL) {
|
||||
if (src_coap_msg_ptr->options_list_ptr->uri_host_len > 0 && src_coap_msg_ptr->options_list_ptr->uri_host_len <= 12) {
|
||||
if (src_options_list_ptr->uri_host_ptr != NULL) {
|
||||
if (src_options_list_ptr->uri_host_len > 0 && src_options_list_ptr->uri_host_len <= 12) {
|
||||
returned_byte_count++;
|
||||
}
|
||||
|
||||
else if (src_coap_msg_ptr->options_list_ptr->uri_host_len >= 13 && src_coap_msg_ptr->options_list_ptr->uri_host_len <= 255) {
|
||||
else if (src_options_list_ptr->uri_host_len >= 13 && src_options_list_ptr->uri_host_len <= 255) {
|
||||
returned_byte_count += 2;
|
||||
}
|
||||
|
||||
|
@ -264,12 +267,12 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_
|
|||
return 0;
|
||||
}
|
||||
|
||||
returned_byte_count += src_coap_msg_ptr->options_list_ptr->uri_host_len;
|
||||
returned_byte_count += src_options_list_ptr->uri_host_len;
|
||||
}
|
||||
/* LOCATION PATH - Repeatable option. Length of this option is 0-255 bytes*/
|
||||
if (src_coap_msg_ptr->options_list_ptr->location_path_ptr != NULL) {
|
||||
repeatable_option_size = sn_coap_builder_options_calc_option_size(src_coap_msg_ptr->options_list_ptr->location_path_len,
|
||||
src_coap_msg_ptr->options_list_ptr->location_path_ptr, COAP_OPTION_LOCATION_PATH);
|
||||
if (src_options_list_ptr->location_path_ptr != NULL) {
|
||||
repeatable_option_size = sn_coap_builder_options_calc_option_size(src_options_list_ptr->location_path_len,
|
||||
src_options_list_ptr->location_path_ptr, COAP_OPTION_LOCATION_PATH);
|
||||
if (repeatable_option_size) {
|
||||
returned_byte_count += repeatable_option_size;
|
||||
} else {
|
||||
|
@ -278,17 +281,17 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_
|
|||
}
|
||||
}
|
||||
/* URI PORT - An integer option, up to 2 bytes */
|
||||
if (src_coap_msg_ptr->options_list_ptr->uri_port != COAP_OPTION_URI_PORT_NONE) {
|
||||
if ((uint32_t) src_coap_msg_ptr->options_list_ptr->uri_port > 0xffff) {
|
||||
if (src_options_list_ptr->uri_port != COAP_OPTION_URI_PORT_NONE) {
|
||||
if ((uint32_t) src_options_list_ptr->uri_port > 0xffff) {
|
||||
tr_error("sn_coap_builder_calc_needed_packet_data_size_2 - uri port too large!");
|
||||
return 0;
|
||||
}
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_coap_msg_ptr->options_list_ptr->uri_port, COAP_OPTION_URI_PORT, &tempInt);
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_options_list_ptr->uri_port, COAP_OPTION_URI_PORT, &tempInt);
|
||||
}
|
||||
/* lOCATION QUERY - Repeatable option. Length of this option is 0-255 bytes */
|
||||
if (src_coap_msg_ptr->options_list_ptr->location_query_ptr != NULL) {
|
||||
repeatable_option_size = sn_coap_builder_options_calc_option_size(src_coap_msg_ptr->options_list_ptr->location_query_len,
|
||||
src_coap_msg_ptr->options_list_ptr->location_query_ptr, COAP_OPTION_LOCATION_QUERY);
|
||||
if (src_options_list_ptr->location_query_ptr != NULL) {
|
||||
repeatable_option_size = sn_coap_builder_options_calc_option_size(src_options_list_ptr->location_query_len,
|
||||
src_options_list_ptr->location_query_ptr, COAP_OPTION_LOCATION_QUERY);
|
||||
if (repeatable_option_size) {
|
||||
returned_byte_count += repeatable_option_size;
|
||||
} else {
|
||||
|
@ -297,16 +300,16 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_
|
|||
}
|
||||
}
|
||||
/* OBSERVE - An integer option, up to 3 bytes */
|
||||
if (src_coap_msg_ptr->options_list_ptr->observe != COAP_OBSERVE_NONE) {
|
||||
if ((uint32_t) src_coap_msg_ptr->options_list_ptr->observe > 0xffffff) {
|
||||
if (src_options_list_ptr->observe != COAP_OBSERVE_NONE) {
|
||||
if ((uint32_t) src_options_list_ptr->observe > 0xffffff) {
|
||||
return 0;
|
||||
}
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_coap_msg_ptr->options_list_ptr->observe, COAP_OPTION_OBSERVE, &tempInt);
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_options_list_ptr->observe, COAP_OPTION_OBSERVE, &tempInt);
|
||||
}
|
||||
/* URI QUERY - Repeatable option. Length of this option is 1-255 */
|
||||
if (src_coap_msg_ptr->options_list_ptr->uri_query_ptr != NULL) {
|
||||
repeatable_option_size = sn_coap_builder_options_calc_option_size(src_coap_msg_ptr->options_list_ptr->uri_query_len,
|
||||
src_coap_msg_ptr->options_list_ptr->uri_query_ptr, COAP_OPTION_URI_QUERY);
|
||||
if (src_options_list_ptr->uri_query_ptr != NULL) {
|
||||
repeatable_option_size = sn_coap_builder_options_calc_option_size(src_options_list_ptr->uri_query_len,
|
||||
src_options_list_ptr->uri_query_ptr, COAP_OPTION_URI_QUERY);
|
||||
if (repeatable_option_size) {
|
||||
returned_byte_count += repeatable_option_size;
|
||||
} else {
|
||||
|
@ -316,28 +319,28 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_
|
|||
}
|
||||
|
||||
/* BLOCK 1 - An integer option, up to 3 bytes */
|
||||
if (src_coap_msg_ptr->options_list_ptr->block1 != COAP_OPTION_BLOCK_NONE) {
|
||||
if ((uint32_t) src_coap_msg_ptr->options_list_ptr->block1 > 0xffffff) {
|
||||
if (src_options_list_ptr->block1 != COAP_OPTION_BLOCK_NONE) {
|
||||
if ((uint32_t) src_options_list_ptr->block1 > 0xffffff) {
|
||||
tr_error("sn_coap_builder_calc_needed_packet_data_size_2 - block1 too large!");
|
||||
return 0;
|
||||
}
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_coap_msg_ptr->options_list_ptr->block1, COAP_OPTION_BLOCK1, &tempInt);
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_options_list_ptr->block1, COAP_OPTION_BLOCK1, &tempInt);
|
||||
}
|
||||
/* SIZE1 - Length of this option is 0-4 bytes */
|
||||
if (src_coap_msg_ptr->options_list_ptr->use_size1) {
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_coap_msg_ptr->options_list_ptr->size1, COAP_OPTION_SIZE1, &tempInt);
|
||||
if (src_options_list_ptr->use_size1) {
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_options_list_ptr->size1, COAP_OPTION_SIZE1, &tempInt);
|
||||
}
|
||||
/* BLOCK 2 - An integer option, up to 3 bytes */
|
||||
if (src_coap_msg_ptr->options_list_ptr->block2 != COAP_OPTION_BLOCK_NONE) {
|
||||
if ((uint32_t) src_coap_msg_ptr->options_list_ptr->block2 > 0xffffff) {
|
||||
if (src_options_list_ptr->block2 != COAP_OPTION_BLOCK_NONE) {
|
||||
if ((uint32_t) src_options_list_ptr->block2 > 0xffffff) {
|
||||
tr_error("sn_coap_builder_calc_needed_packet_data_size_2 - block2 too large!");
|
||||
return 0;
|
||||
}
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_coap_msg_ptr->options_list_ptr->block2, COAP_OPTION_BLOCK2, &tempInt);
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_options_list_ptr->block2, COAP_OPTION_BLOCK2, &tempInt);
|
||||
}
|
||||
/* SIZE2 - Length of this option is 0-4 bytes */
|
||||
if (src_coap_msg_ptr->options_list_ptr->use_size2) {
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_coap_msg_ptr->options_list_ptr->size2, COAP_OPTION_SIZE2, &tempInt);
|
||||
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_options_list_ptr->size2, COAP_OPTION_SIZE2, &tempInt);
|
||||
}
|
||||
}
|
||||
#if SN_COAP_BLOCKWISE_ENABLED || SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE
|
||||
|
@ -354,12 +357,12 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_
|
|||
if (src_coap_msg_ptr->payload_len) {
|
||||
returned_byte_count ++; /* For payload marker */
|
||||
}
|
||||
returned_byte_count += sn_coap_builder_options_calculate_jump_need(src_coap_msg_ptr/*, 0*/);
|
||||
returned_byte_count += sn_coap_builder_options_calculate_jump_need(src_coap_msg_ptr);
|
||||
}
|
||||
return returned_byte_count;
|
||||
}
|
||||
/**
|
||||
* \fn static uint8_t sn_coap_builder_options_calculate_jump_need(sn_coap_hdr_s *src_coap_msg_ptr, uint8_t block_option)
|
||||
* \fn static uint8_t sn_coap_builder_options_calculate_jump_need(sn_coap_hdr_s *src_coap_msg_ptr)
|
||||
*
|
||||
* \brief Checks if there is need for option jump
|
||||
*
|
||||
|
@ -370,43 +373,47 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_
|
|||
* \return Returns bytes needed for jumping
|
||||
*/
|
||||
|
||||
static uint8_t sn_coap_builder_options_calculate_jump_need(sn_coap_hdr_s *src_coap_msg_ptr/*, uint8_t block_option*/)
|
||||
static uint8_t sn_coap_builder_options_calculate_jump_need(const sn_coap_hdr_s *src_coap_msg_ptr)
|
||||
{
|
||||
uint8_t previous_option_number = 0;
|
||||
uint8_t needed_space = 0;
|
||||
|
||||
if (src_coap_msg_ptr->options_list_ptr != NULL) {
|
||||
const sn_coap_options_list_s* options_list_ptr = src_coap_msg_ptr->options_list_ptr;
|
||||
|
||||
if (options_list_ptr != NULL) {
|
||||
|
||||
|
||||
/* If option numbers greater than 12 is not used, then jumping is not needed */
|
||||
//TODO: Check if this is really needed! Does it enhance perf? If not -> remove
|
||||
if (!src_coap_msg_ptr->options_list_ptr->uri_query_ptr &&
|
||||
src_coap_msg_ptr->options_list_ptr->accept == COAP_CT_NONE &&
|
||||
!src_coap_msg_ptr->options_list_ptr->location_query_ptr &&
|
||||
src_coap_msg_ptr->options_list_ptr->block2 == COAP_OPTION_BLOCK_NONE &&
|
||||
src_coap_msg_ptr->options_list_ptr->block1 == COAP_OPTION_BLOCK_NONE &&
|
||||
!src_coap_msg_ptr->options_list_ptr->proxy_uri_ptr &&
|
||||
src_coap_msg_ptr->options_list_ptr->max_age == COAP_OPTION_MAX_AGE_DEFAULT &&
|
||||
!src_coap_msg_ptr->options_list_ptr->use_size1 &&
|
||||
!src_coap_msg_ptr->options_list_ptr->use_size2) {
|
||||
if (!options_list_ptr->uri_query_ptr &&
|
||||
options_list_ptr->accept == COAP_CT_NONE &&
|
||||
!options_list_ptr->location_query_ptr &&
|
||||
options_list_ptr->block2 == COAP_OPTION_BLOCK_NONE &&
|
||||
options_list_ptr->block1 == COAP_OPTION_BLOCK_NONE &&
|
||||
!options_list_ptr->proxy_uri_ptr &&
|
||||
options_list_ptr->max_age == COAP_OPTION_MAX_AGE_DEFAULT &&
|
||||
!options_list_ptr->use_size1 &&
|
||||
!options_list_ptr->use_size2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (src_coap_msg_ptr->options_list_ptr->uri_host_ptr != NULL) {
|
||||
if (options_list_ptr->uri_host_ptr != NULL) {
|
||||
previous_option_number = (COAP_OPTION_URI_HOST);
|
||||
}
|
||||
|
||||
if (src_coap_msg_ptr->options_list_ptr->etag_ptr != NULL) {
|
||||
if (options_list_ptr->etag_ptr != NULL) {
|
||||
previous_option_number = (COAP_OPTION_ETAG);
|
||||
}
|
||||
|
||||
if (src_coap_msg_ptr->options_list_ptr->observe != COAP_OBSERVE_NONE) {
|
||||
if (options_list_ptr->observe != COAP_OBSERVE_NONE) {
|
||||
previous_option_number = (COAP_OPTION_OBSERVE);
|
||||
}
|
||||
|
||||
if (src_coap_msg_ptr->options_list_ptr->uri_port != COAP_OPTION_URI_PORT_NONE) {
|
||||
if (options_list_ptr->uri_port != COAP_OPTION_URI_PORT_NONE) {
|
||||
previous_option_number = (COAP_OPTION_URI_PORT);
|
||||
}
|
||||
|
||||
if (src_coap_msg_ptr->options_list_ptr->location_path_ptr != NULL) {
|
||||
if (options_list_ptr->location_path_ptr != NULL) {
|
||||
previous_option_number = (COAP_OPTION_LOCATION_PATH);
|
||||
}
|
||||
|
||||
|
@ -416,50 +423,51 @@ static uint8_t sn_coap_builder_options_calculate_jump_need(sn_coap_hdr_s *src_co
|
|||
if (src_coap_msg_ptr->content_format != COAP_CT_NONE) {
|
||||
previous_option_number = (COAP_OPTION_CONTENT_FORMAT);
|
||||
}
|
||||
if (src_coap_msg_ptr->options_list_ptr->max_age != COAP_OPTION_MAX_AGE_DEFAULT) {
|
||||
|
||||
if (options_list_ptr->max_age != COAP_OPTION_MAX_AGE_DEFAULT) {
|
||||
if ((COAP_OPTION_MAX_AGE - previous_option_number) > 12) {
|
||||
needed_space += 1;
|
||||
}
|
||||
previous_option_number = (COAP_OPTION_MAX_AGE);
|
||||
}
|
||||
|
||||
if (src_coap_msg_ptr->options_list_ptr->uri_query_ptr != NULL) {
|
||||
if (options_list_ptr->uri_query_ptr != NULL) {
|
||||
if ((COAP_OPTION_URI_QUERY - previous_option_number) > 12) {
|
||||
needed_space += 1;
|
||||
}
|
||||
previous_option_number = (COAP_OPTION_URI_QUERY);
|
||||
}
|
||||
if (src_coap_msg_ptr->options_list_ptr->accept != COAP_CT_NONE) {
|
||||
if (options_list_ptr->accept != COAP_CT_NONE) {
|
||||
if ((COAP_OPTION_ACCEPT - previous_option_number) > 12) {
|
||||
needed_space += 1;
|
||||
}
|
||||
previous_option_number = (COAP_OPTION_ACCEPT);
|
||||
}
|
||||
if (src_coap_msg_ptr->options_list_ptr->location_query_ptr != NULL) {
|
||||
if (options_list_ptr->location_query_ptr != NULL) {
|
||||
if ((COAP_OPTION_LOCATION_QUERY - previous_option_number) > 12) {
|
||||
needed_space += 1;
|
||||
}
|
||||
previous_option_number = (COAP_OPTION_LOCATION_QUERY);
|
||||
}
|
||||
if (src_coap_msg_ptr->options_list_ptr->block2 != COAP_OPTION_BLOCK_NONE) {
|
||||
if (options_list_ptr->block2 != COAP_OPTION_BLOCK_NONE) {
|
||||
if ((COAP_OPTION_BLOCK2 - previous_option_number) > 12 ){
|
||||
needed_space += 1;
|
||||
}
|
||||
previous_option_number = (COAP_OPTION_BLOCK2);
|
||||
}
|
||||
if (src_coap_msg_ptr->options_list_ptr->block1 != COAP_OPTION_BLOCK_NONE) {
|
||||
if (options_list_ptr->block1 != COAP_OPTION_BLOCK_NONE) {
|
||||
if ((COAP_OPTION_BLOCK1 - previous_option_number) > 12 ){
|
||||
needed_space += 1;
|
||||
}
|
||||
previous_option_number = (COAP_OPTION_BLOCK1);
|
||||
}
|
||||
if (src_coap_msg_ptr->options_list_ptr->use_size2) {
|
||||
if (options_list_ptr->use_size2) {
|
||||
if ((COAP_OPTION_SIZE2 - previous_option_number) > 12) {
|
||||
needed_space += 1;
|
||||
}
|
||||
previous_option_number = (COAP_OPTION_SIZE2);
|
||||
}
|
||||
if (src_coap_msg_ptr->options_list_ptr->proxy_uri_ptr != NULL) {
|
||||
if (options_list_ptr->proxy_uri_ptr != NULL) {
|
||||
if ((COAP_OPTION_PROXY_URI - previous_option_number) > 12) {
|
||||
needed_space += 1;
|
||||
}
|
||||
|
@ -468,7 +476,7 @@ static uint8_t sn_coap_builder_options_calculate_jump_need(sn_coap_hdr_s *src_co
|
|||
}
|
||||
previous_option_number = (COAP_OPTION_PROXY_URI);
|
||||
}
|
||||
if (src_coap_msg_ptr->options_list_ptr->use_size1 ) {
|
||||
if (options_list_ptr->use_size1) {
|
||||
if ((COAP_OPTION_SIZE1 - previous_option_number) > 12) {
|
||||
needed_space += 1;
|
||||
}
|
||||
|
@ -499,7 +507,7 @@ static uint8_t sn_coap_builder_options_calculate_jump_need(sn_coap_hdr_s *src_co
|
|||
*
|
||||
* \return Return value is 0 in ok case and -1 in failure case
|
||||
**************************************************************************** */
|
||||
static int8_t sn_coap_builder_header_build(uint8_t **dst_packet_data_pptr, sn_coap_hdr_s *src_coap_msg_ptr)
|
||||
static int8_t sn_coap_builder_header_build(uint8_t **dst_packet_data_pptr, const sn_coap_hdr_s *src_coap_msg_ptr)
|
||||
{
|
||||
/* * * * Check validity of Header values * * * */
|
||||
if (sn_coap_header_validity_check(src_coap_msg_ptr, COAP_VERSION) != 0) {
|
||||
|
@ -507,25 +515,19 @@ static int8_t sn_coap_builder_header_build(uint8_t **dst_packet_data_pptr, sn_co
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* * * Add CoAP Version * * */
|
||||
**dst_packet_data_pptr += COAP_VERSION;
|
||||
uint8_t* dest_packet = *dst_packet_data_pptr;
|
||||
|
||||
/* * * Add Message type * * */
|
||||
**dst_packet_data_pptr += src_coap_msg_ptr->msg_type;
|
||||
/* Set CoAP Version, Message type and Token length */
|
||||
dest_packet[0] = COAP_VERSION | src_coap_msg_ptr->msg_type | src_coap_msg_ptr->token_len;
|
||||
|
||||
/* * * Add Token length * * */
|
||||
**dst_packet_data_pptr += (src_coap_msg_ptr->token_len);
|
||||
|
||||
(*dst_packet_data_pptr) ++;
|
||||
/* * * Add Message code * * */
|
||||
**dst_packet_data_pptr = src_coap_msg_ptr->msg_code;
|
||||
(*dst_packet_data_pptr) ++;
|
||||
dest_packet[1] = src_coap_msg_ptr->msg_code;
|
||||
|
||||
/* * * Add Message ID * * */
|
||||
**dst_packet_data_pptr = (uint8_t)(src_coap_msg_ptr->msg_id >> COAP_HEADER_MSG_ID_MSB_SHIFT); /* MSB part */
|
||||
(*dst_packet_data_pptr) ++;
|
||||
**dst_packet_data_pptr = (uint8_t)src_coap_msg_ptr->msg_id; /* LSB part */
|
||||
(*dst_packet_data_pptr) ++;
|
||||
dest_packet[2] = (uint8_t)(src_coap_msg_ptr->msg_id >> COAP_HEADER_MSG_ID_MSB_SHIFT); /* MSB part */
|
||||
dest_packet[3] = (uint8_t)src_coap_msg_ptr->msg_id; /* LSB part */
|
||||
|
||||
*dst_packet_data_pptr = dest_packet + 4;
|
||||
|
||||
/* Success */
|
||||
return 0;
|
||||
|
@ -542,7 +544,7 @@ static int8_t sn_coap_builder_header_build(uint8_t **dst_packet_data_pptr, sn_co
|
|||
*
|
||||
* \return Return value is 0 in every case
|
||||
*/
|
||||
static int8_t sn_coap_builder_options_build(uint8_t **dst_packet_data_pptr, sn_coap_hdr_s *src_coap_msg_ptr)
|
||||
static int8_t sn_coap_builder_options_build(uint8_t **dst_packet_data_pptr, const sn_coap_hdr_s *src_coap_msg_ptr)
|
||||
{
|
||||
/* * * * Check if Options are used at all * * * */
|
||||
if (src_coap_msg_ptr->uri_path_ptr == NULL && src_coap_msg_ptr->token_ptr == NULL &&
|
||||
|
@ -567,35 +569,37 @@ static int8_t sn_coap_builder_options_build(uint8_t **dst_packet_data_pptr, sn_c
|
|||
|
||||
//missing: COAP_OPTION_IF_MATCH, COAP_OPTION_IF_NONE_MATCH, COAP_OPTION_SIZE
|
||||
|
||||
const sn_coap_options_list_s *src_options_list_ptr = src_coap_msg_ptr->options_list_ptr;
|
||||
|
||||
/* Check if less used options are used at all */
|
||||
if (src_coap_msg_ptr->options_list_ptr != NULL) {
|
||||
if (src_options_list_ptr != NULL) {
|
||||
/* * * * Build Uri-Host option * * * */
|
||||
sn_coap_builder_options_build_add_one_option(dst_packet_data_pptr, src_coap_msg_ptr->options_list_ptr->uri_host_len,
|
||||
src_coap_msg_ptr->options_list_ptr->uri_host_ptr, COAP_OPTION_URI_HOST, &previous_option_number);
|
||||
sn_coap_builder_options_build_add_one_option(dst_packet_data_pptr, src_options_list_ptr->uri_host_len,
|
||||
src_options_list_ptr->uri_host_ptr, COAP_OPTION_URI_HOST, &previous_option_number);
|
||||
|
||||
/* * * * Build ETag option * * * */
|
||||
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, &src_coap_msg_ptr->options_list_ptr->etag_ptr,
|
||||
(uint16_t *)&src_coap_msg_ptr->options_list_ptr->etag_len, COAP_OPTION_ETAG, &previous_option_number);
|
||||
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, src_options_list_ptr->etag_ptr,
|
||||
src_options_list_ptr->etag_len, COAP_OPTION_ETAG, &previous_option_number);
|
||||
|
||||
/* * * * Build Observe option * * * * */
|
||||
if (src_coap_msg_ptr->options_list_ptr->observe != COAP_OBSERVE_NONE) {
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_coap_msg_ptr->options_list_ptr->observe,
|
||||
if (src_options_list_ptr->observe != COAP_OBSERVE_NONE) {
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_options_list_ptr->observe,
|
||||
COAP_OPTION_OBSERVE, &previous_option_number);
|
||||
}
|
||||
|
||||
/* * * * Build Uri-Port option * * * */
|
||||
if (src_coap_msg_ptr->options_list_ptr->uri_port != COAP_OPTION_URI_PORT_NONE) {
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_coap_msg_ptr->options_list_ptr->uri_port,
|
||||
if (src_options_list_ptr->uri_port != COAP_OPTION_URI_PORT_NONE) {
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_options_list_ptr->uri_port,
|
||||
COAP_OPTION_URI_PORT, &previous_option_number);
|
||||
}
|
||||
|
||||
/* * * * Build Location-Path option * * * */
|
||||
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, &src_coap_msg_ptr->options_list_ptr->location_path_ptr,
|
||||
&src_coap_msg_ptr->options_list_ptr->location_path_len, COAP_OPTION_LOCATION_PATH, &previous_option_number);
|
||||
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, src_options_list_ptr->location_path_ptr,
|
||||
src_options_list_ptr->location_path_len, COAP_OPTION_LOCATION_PATH, &previous_option_number);
|
||||
}
|
||||
/* * * * Build Uri-Path option * * * */
|
||||
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, &src_coap_msg_ptr->uri_path_ptr,
|
||||
&src_coap_msg_ptr->uri_path_len, COAP_OPTION_URI_PATH, &previous_option_number);
|
||||
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, src_coap_msg_ptr->uri_path_ptr,
|
||||
src_coap_msg_ptr->uri_path_len, COAP_OPTION_URI_PATH, &previous_option_number);
|
||||
|
||||
/* * * * Build Content-Type option * * * */
|
||||
if (src_coap_msg_ptr->content_format != COAP_CT_NONE) {
|
||||
|
@ -603,55 +607,53 @@ static int8_t sn_coap_builder_options_build(uint8_t **dst_packet_data_pptr, sn_c
|
|||
COAP_OPTION_CONTENT_FORMAT, &previous_option_number);
|
||||
}
|
||||
|
||||
if (src_coap_msg_ptr->options_list_ptr != NULL) {
|
||||
if (src_options_list_ptr != NULL) {
|
||||
/* * * * Build Max-Age option * * * */
|
||||
if (src_coap_msg_ptr->options_list_ptr->max_age != COAP_OPTION_MAX_AGE_DEFAULT) {
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_coap_msg_ptr->options_list_ptr->max_age,
|
||||
if (src_options_list_ptr->max_age != COAP_OPTION_MAX_AGE_DEFAULT) {
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_options_list_ptr->max_age,
|
||||
COAP_OPTION_MAX_AGE, &previous_option_number);
|
||||
}
|
||||
|
||||
/* * * * Build Uri-Query option * * * * */
|
||||
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, &src_coap_msg_ptr->options_list_ptr->uri_query_ptr,
|
||||
&src_coap_msg_ptr->options_list_ptr->uri_query_len, COAP_OPTION_URI_QUERY, &previous_option_number);
|
||||
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, src_options_list_ptr->uri_query_ptr,
|
||||
src_options_list_ptr->uri_query_len, COAP_OPTION_URI_QUERY, &previous_option_number);
|
||||
|
||||
/* * * * Build Accept option * * * * */
|
||||
if (src_coap_msg_ptr->options_list_ptr->accept != COAP_CT_NONE) {
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_coap_msg_ptr->options_list_ptr->accept,
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_options_list_ptr->accept,
|
||||
COAP_OPTION_ACCEPT, &previous_option_number);
|
||||
}
|
||||
}
|
||||
|
||||
if (src_coap_msg_ptr->options_list_ptr != NULL) {
|
||||
/* * * * Build Location-Query option * * * */
|
||||
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, &src_coap_msg_ptr->options_list_ptr->location_query_ptr,
|
||||
&src_coap_msg_ptr->options_list_ptr->location_query_len, COAP_OPTION_LOCATION_QUERY, &previous_option_number);
|
||||
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, src_options_list_ptr->location_query_ptr,
|
||||
src_options_list_ptr->location_query_len, COAP_OPTION_LOCATION_QUERY, &previous_option_number);
|
||||
|
||||
/* * * * Build Block2 option * * * * */
|
||||
if (src_coap_msg_ptr->options_list_ptr->block2 != COAP_OPTION_BLOCK_NONE) {
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_coap_msg_ptr->options_list_ptr->block2,
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_options_list_ptr->block2,
|
||||
COAP_OPTION_BLOCK2, &previous_option_number);
|
||||
}
|
||||
|
||||
/* * * * Build Block1 option * * * * */
|
||||
if (src_coap_msg_ptr->options_list_ptr->block1 != COAP_OPTION_BLOCK_NONE) {
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_coap_msg_ptr->options_list_ptr->block1,
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_options_list_ptr->block1,
|
||||
COAP_OPTION_BLOCK1, &previous_option_number);
|
||||
}
|
||||
|
||||
/* * * * Build Size2 option * * * */
|
||||
if (src_coap_msg_ptr->options_list_ptr->use_size2) {
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_coap_msg_ptr->options_list_ptr->size2,
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_options_list_ptr->size2,
|
||||
COAP_OPTION_SIZE2, &previous_option_number);
|
||||
}
|
||||
|
||||
/* * * * Build Proxy-Uri option * * * */
|
||||
sn_coap_builder_options_build_add_one_option(dst_packet_data_pptr, src_coap_msg_ptr->options_list_ptr->proxy_uri_len,
|
||||
src_coap_msg_ptr->options_list_ptr->proxy_uri_ptr, COAP_OPTION_PROXY_URI, &previous_option_number);
|
||||
sn_coap_builder_options_build_add_one_option(dst_packet_data_pptr, src_options_list_ptr->proxy_uri_len,
|
||||
src_options_list_ptr->proxy_uri_ptr, COAP_OPTION_PROXY_URI, &previous_option_number);
|
||||
|
||||
|
||||
/* * * * Build Size1 option * * * */
|
||||
if (src_coap_msg_ptr->options_list_ptr->use_size1) {
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_coap_msg_ptr->options_list_ptr->size1,
|
||||
if (src_options_list_ptr->use_size1) {
|
||||
sn_coap_builder_options_build_add_uint_option(dst_packet_data_pptr, src_options_list_ptr->size1,
|
||||
COAP_OPTION_SIZE1, &previous_option_number);
|
||||
}
|
||||
}
|
||||
|
@ -676,7 +678,7 @@ static int8_t sn_coap_builder_options_build(uint8_t **dst_packet_data_pptr, sn_c
|
|||
* \return Return value is 0 if option was not added, 1 if added
|
||||
*/
|
||||
static int16_t sn_coap_builder_options_build_add_one_option(uint8_t **dst_packet_data_pptr, uint16_t option_len,
|
||||
uint8_t *option_ptr, sn_coap_option_numbers_e option_number, uint16_t *previous_option_number)
|
||||
const uint8_t *option_ptr, sn_coap_option_numbers_e option_number, uint16_t *previous_option_number)
|
||||
{
|
||||
/* Check if there is option at all */
|
||||
if (option_ptr != NULL) {
|
||||
|
@ -686,61 +688,67 @@ static int16_t sn_coap_builder_options_build_add_one_option(uint8_t **dst_packet
|
|||
|
||||
/* * * Build option header * * */
|
||||
|
||||
uint8_t first_byte;
|
||||
|
||||
/* First option length without extended part */
|
||||
if (option_len <= 12) {
|
||||
**dst_packet_data_pptr = option_len;
|
||||
first_byte = option_len;
|
||||
}
|
||||
|
||||
else if (option_len > 12 && option_len < 269) {
|
||||
**dst_packet_data_pptr = 0x0D;
|
||||
first_byte = 0x0D;
|
||||
}
|
||||
|
||||
else if (option_len >= 269) {
|
||||
**dst_packet_data_pptr = 0x0E;
|
||||
else /*if (option_len >= 269)*/ {
|
||||
first_byte = 0x0E;
|
||||
}
|
||||
|
||||
uint8_t *dest_packet = *dst_packet_data_pptr;
|
||||
|
||||
/* Then option delta with extensions, and move pointer */
|
||||
if (option_delta <= 12) {
|
||||
**dst_packet_data_pptr += (option_delta << 4);
|
||||
*dst_packet_data_pptr += 1;
|
||||
dest_packet[0] = first_byte + (option_delta << 4);
|
||||
dest_packet += 1;
|
||||
}
|
||||
|
||||
else if (option_delta > 12 && option_delta < 269) {
|
||||
**dst_packet_data_pptr += 0xD0;
|
||||
dest_packet[0] = first_byte + 0xD0;
|
||||
option_delta -= 13;
|
||||
|
||||
*(*dst_packet_data_pptr + 1) = (uint8_t)option_delta;
|
||||
*dst_packet_data_pptr += 2;
|
||||
dest_packet[1] = (uint8_t)option_delta;
|
||||
dest_packet += 2;
|
||||
}
|
||||
//This is currently dead code (but possibly needed in future)
|
||||
else if (option_delta >= 269) {
|
||||
**dst_packet_data_pptr += 0xE0;
|
||||
else /*if (option_delta >= 269)*/ {
|
||||
dest_packet[0] = first_byte + 0xE0;
|
||||
option_delta -= 269;
|
||||
|
||||
*(*dst_packet_data_pptr + 2) = (uint8_t)option_delta;
|
||||
*(*dst_packet_data_pptr + 1) = (option_delta >> 8);
|
||||
*dst_packet_data_pptr += 3;
|
||||
dest_packet[1] = (option_delta >> 8);
|
||||
dest_packet[2] = (uint8_t)option_delta;
|
||||
dest_packet += 3;
|
||||
}
|
||||
|
||||
/* Now option length extensions, if needed */
|
||||
if (option_len > 12 && option_len < 269) {
|
||||
**dst_packet_data_pptr = (uint8_t)(option_len - 13);
|
||||
*dst_packet_data_pptr += 1;
|
||||
dest_packet[0] = (uint8_t)(option_len - 13);
|
||||
dest_packet += 1;
|
||||
}
|
||||
|
||||
else if (option_len >= 269) {
|
||||
*(*dst_packet_data_pptr + 1) = (uint8_t)(option_len - 269);
|
||||
**dst_packet_data_pptr = ((option_len - 269) >> 8);
|
||||
*dst_packet_data_pptr += 2;
|
||||
dest_packet[0] = ((option_len - 269) >> 8);
|
||||
dest_packet[1] = (uint8_t)(option_len - 269);
|
||||
dest_packet += 2;
|
||||
}
|
||||
|
||||
*previous_option_number = option_number;
|
||||
|
||||
/* Write Option value */
|
||||
memcpy(*dst_packet_data_pptr, option_ptr, option_len);
|
||||
memcpy(dest_packet, option_ptr, option_len);
|
||||
|
||||
/* Increase destination Packet data pointer */
|
||||
(*dst_packet_data_pptr) += option_len;
|
||||
dest_packet += option_len;
|
||||
|
||||
*dst_packet_data_pptr = dest_packet;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -775,11 +783,9 @@ static uint8_t sn_coap_builder_options_build_add_uint_option(uint8_t **dst_packe
|
|||
|
||||
/* If output pointer isn't NULL, write it out */
|
||||
if (dst_packet_data_pptr) {
|
||||
int16_t ret = sn_coap_builder_options_build_add_one_option(dst_packet_data_pptr, len, payload, option_number, previous_option_number);
|
||||
/* Allow for failure returns when writing (why even permit failure returns?) */
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
// No need to check & handle return value, as the function returns failure only if the option pointer is zero
|
||||
// and it is pointing to a local variable here.
|
||||
sn_coap_builder_options_build_add_one_option(dst_packet_data_pptr, len, payload, option_number, previous_option_number);
|
||||
}
|
||||
|
||||
/* Return the total option size */
|
||||
|
@ -793,21 +799,21 @@ static uint8_t sn_coap_builder_options_build_add_uint_option(uint8_t **dst_packe
|
|||
*
|
||||
* \param **dst_packet_data_pptr is destination for built Packet data
|
||||
*
|
||||
* \param uint8_t **src_pptr
|
||||
* \param uint8_t **src_ptr
|
||||
*
|
||||
* \param uint16_t *src_len_ptr
|
||||
* \param uint16_t src_len
|
||||
*
|
||||
* \paramsn_coap_option_numbers_e option option to be added
|
||||
*
|
||||
* \return Return value is 0 always
|
||||
*/
|
||||
static int16_t sn_coap_builder_options_build_add_multiple_option(uint8_t **dst_packet_data_pptr, uint8_t **src_pptr, uint16_t *src_len_ptr, sn_coap_option_numbers_e option, uint16_t *previous_option_number)
|
||||
static void sn_coap_builder_options_build_add_multiple_option(uint8_t **dst_packet_data_pptr, const uint8_t *src_pptr, uint16_t src_len, sn_coap_option_numbers_e option, uint16_t *previous_option_number)
|
||||
{
|
||||
/* Check if there is option at all */
|
||||
if (*src_pptr != NULL) {
|
||||
uint8_t *query_ptr = *src_pptr;
|
||||
if (src_pptr != NULL) {
|
||||
const uint8_t *query_ptr = src_pptr;
|
||||
uint8_t query_part_count = 0;
|
||||
uint16_t query_len = *src_len_ptr;
|
||||
uint16_t query_len = src_len;
|
||||
uint8_t i = 0;
|
||||
uint16_t query_part_offset = 0;
|
||||
|
||||
|
@ -823,11 +829,10 @@ static int16_t sn_coap_builder_options_build_add_multiple_option(uint8_t **dst_p
|
|||
query_part_offset = sn_coap_builder_options_get_option_part_position(query_len, query_ptr, i, option);
|
||||
|
||||
/* Add Uri-query's one part to Options */
|
||||
sn_coap_builder_options_build_add_one_option(dst_packet_data_pptr, one_query_part_len, *src_pptr + query_part_offset, option, previous_option_number);
|
||||
sn_coap_builder_options_build_add_one_option(dst_packet_data_pptr, one_query_part_len, src_pptr + query_part_offset, option, previous_option_number);
|
||||
}
|
||||
}
|
||||
/* Success */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -842,7 +847,7 @@ static int16_t sn_coap_builder_options_build_add_multiple_option(uint8_t **dst_p
|
|||
*
|
||||
* \return Return value is count of needed memory as bytes for Uri-query option
|
||||
*/
|
||||
static uint16_t sn_coap_builder_options_calc_option_size(uint16_t query_len, uint8_t *query_ptr, sn_coap_option_numbers_e option)
|
||||
static uint16_t sn_coap_builder_options_calc_option_size(uint16_t query_len, const uint8_t *query_ptr, sn_coap_option_numbers_e option)
|
||||
{
|
||||
uint8_t query_part_count = sn_coap_builder_options_get_option_part_count(query_len, query_ptr, option);
|
||||
uint8_t i = 0;
|
||||
|
@ -923,7 +928,7 @@ static uint16_t sn_coap_builder_options_calc_option_size(uint16_t query_len, uin
|
|||
*
|
||||
* \return Return value is count of query parts
|
||||
*/
|
||||
static uint8_t sn_coap_builder_options_get_option_part_count(uint16_t query_len, uint8_t *query_ptr, sn_coap_option_numbers_e option)
|
||||
static uint8_t sn_coap_builder_options_get_option_part_count(uint16_t query_len, const uint8_t *query_ptr, sn_coap_option_numbers_e option)
|
||||
{
|
||||
uint8_t returned_query_count = 0;
|
||||
uint16_t query_len_index = 0;
|
||||
|
@ -963,7 +968,7 @@ static uint8_t sn_coap_builder_options_get_option_part_count(uint16_t query_len,
|
|||
*
|
||||
* \return Return value is length of query part
|
||||
*/
|
||||
static uint16_t sn_coap_builder_options_get_option_part_length_from_whole_option_string(uint16_t query_len, uint8_t *query_ptr,
|
||||
static uint16_t sn_coap_builder_options_get_option_part_length_from_whole_option_string(uint16_t query_len, const uint8_t *query_ptr,
|
||||
uint8_t query_index, sn_coap_option_numbers_e option)
|
||||
{
|
||||
uint16_t returned_query_part_len = 0;
|
||||
|
@ -1021,7 +1026,7 @@ static uint16_t sn_coap_builder_options_get_option_part_length_from_whole_option
|
|||
* \return Return value is position (= offset) of query part in whole query. In
|
||||
* fail cases -1 is returned.
|
||||
*/
|
||||
static int16_t sn_coap_builder_options_get_option_part_position(uint16_t query_len, uint8_t *query_ptr,
|
||||
static int16_t sn_coap_builder_options_get_option_part_position(uint16_t query_len, const uint8_t *query_ptr,
|
||||
uint8_t query_index, sn_coap_option_numbers_e option)
|
||||
{
|
||||
uint16_t returned_query_part_offset = 0;
|
||||
|
@ -1076,7 +1081,7 @@ static int16_t sn_coap_builder_options_get_option_part_position(uint16_t query_l
|
|||
*
|
||||
* \param *src_coap_msg_ptr is source for building Packet data
|
||||
*/
|
||||
static void sn_coap_builder_payload_build(uint8_t **dst_packet_data_pptr, sn_coap_hdr_s *src_coap_msg_ptr)
|
||||
static void sn_coap_builder_payload_build(uint8_t **dst_packet_data_pptr, const sn_coap_hdr_s *src_coap_msg_ptr)
|
||||
{
|
||||
/* Check if Payload is used at all */
|
||||
if (src_coap_msg_ptr->payload_len && src_coap_msg_ptr->payload_ptr != NULL) {
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
* \return Return value is status of validity check. In ok cases 0 and in
|
||||
* failure cases -1
|
||||
*/
|
||||
int8_t sn_coap_header_validity_check(sn_coap_hdr_s *src_coap_msg_ptr, coap_version_e coap_version)
|
||||
int8_t sn_coap_header_validity_check(const sn_coap_hdr_s *src_coap_msg_ptr, coap_version_e coap_version)
|
||||
{
|
||||
/* * Check validity of CoAP Version * */
|
||||
if (coap_version != COAP_VERSION_1) {
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
static void sn_coap_parser_header_parse(uint8_t **packet_data_pptr, sn_coap_hdr_s *dst_coap_msg_ptr, coap_version_e *coap_version_ptr);
|
||||
static int8_t sn_coap_parser_options_parse(struct coap_s *handle, uint8_t **packet_data_pptr, sn_coap_hdr_s *dst_coap_msg_ptr, uint8_t *packet_data_start_ptr, uint16_t packet_len);
|
||||
static int8_t sn_coap_parser_options_parse_multiple_options(struct coap_s *handle, uint8_t **packet_data_pptr, uint16_t packet_left_len, uint8_t **dst_pptr, uint16_t *dst_len_ptr, sn_coap_option_numbers_e option, uint16_t option_number_len);
|
||||
static int16_t sn_coap_parser_options_count_needed_memory_multiple_option(uint8_t *packet_data_ptr, uint16_t packet_left_len, sn_coap_option_numbers_e option, uint16_t option_number_len);
|
||||
static int16_t sn_coap_parser_options_count_needed_memory_multiple_option(const uint8_t *packet_data_ptr, uint16_t packet_left_len, sn_coap_option_numbers_e option, uint16_t option_number_len);
|
||||
static int8_t sn_coap_parser_payload_parse(uint16_t packet_data_len, uint8_t *packet_data_start_ptr, uint8_t **packet_data_pptr, sn_coap_hdr_s *dst_coap_msg_ptr);
|
||||
|
||||
sn_coap_hdr_s *sn_coap_parser_init_message(sn_coap_hdr_s *coap_msg_ptr)
|
||||
|
@ -64,6 +64,29 @@ sn_coap_hdr_s *sn_coap_parser_init_message(sn_coap_hdr_s *coap_msg_ptr)
|
|||
return coap_msg_ptr;
|
||||
}
|
||||
|
||||
sn_coap_hdr_s *sn_coap_parser_alloc_message_with_options(struct coap_s *handle)
|
||||
{
|
||||
// check the handle just as in any other place
|
||||
if (handle == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sn_coap_hdr_s *coap_msg_ptr = sn_coap_parser_alloc_message(handle);
|
||||
|
||||
sn_coap_options_list_s *options_list_ptr = sn_coap_parser_alloc_options(handle, coap_msg_ptr);
|
||||
|
||||
if ((coap_msg_ptr == NULL) || (options_list_ptr == NULL)) {
|
||||
|
||||
// oops, out of memory free if got already any
|
||||
handle->sn_coap_protocol_free(coap_msg_ptr);
|
||||
handle->sn_coap_protocol_free(options_list_ptr);
|
||||
|
||||
coap_msg_ptr = NULL;
|
||||
}
|
||||
|
||||
return coap_msg_ptr;
|
||||
}
|
||||
|
||||
sn_coap_hdr_s *sn_coap_parser_alloc_message(struct coap_s *handle)
|
||||
{
|
||||
sn_coap_hdr_s *returned_coap_msg_ptr;
|
||||
|
@ -81,6 +104,8 @@ sn_coap_hdr_s *sn_coap_parser_alloc_message(struct coap_s *handle)
|
|||
|
||||
sn_coap_options_list_s *sn_coap_parser_alloc_options(struct coap_s *handle, sn_coap_hdr_s *coap_msg_ptr)
|
||||
{
|
||||
sn_coap_options_list_s *options_list_ptr;
|
||||
|
||||
/* * * * Check given pointers * * * */
|
||||
if (handle == NULL || coap_msg_ptr == NULL) {
|
||||
return NULL;
|
||||
|
@ -92,24 +117,23 @@ sn_coap_options_list_s *sn_coap_parser_alloc_options(struct coap_s *handle, sn_c
|
|||
}
|
||||
|
||||
/* * * * Allocate memory for options and initialize allocated memory with with default values * * * */
|
||||
coap_msg_ptr->options_list_ptr = handle->sn_coap_protocol_malloc(sizeof(sn_coap_options_list_s));
|
||||
/* XXX not technically legal to memset pointers to 0 */
|
||||
options_list_ptr = sn_coap_protocol_calloc(handle, sizeof(sn_coap_options_list_s));
|
||||
|
||||
if (coap_msg_ptr->options_list_ptr == NULL) {
|
||||
if (options_list_ptr == NULL) {
|
||||
tr_error("sn_coap_parser_alloc_options - failed to allocate options list!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* XXX not technically legal to memset pointers to 0 */
|
||||
memset(coap_msg_ptr->options_list_ptr, 0x00, sizeof(sn_coap_options_list_s));
|
||||
coap_msg_ptr->options_list_ptr = options_list_ptr;
|
||||
|
||||
coap_msg_ptr->options_list_ptr->max_age = 0;
|
||||
coap_msg_ptr->options_list_ptr->uri_port = COAP_OPTION_URI_PORT_NONE;
|
||||
coap_msg_ptr->options_list_ptr->observe = COAP_OBSERVE_NONE;
|
||||
coap_msg_ptr->options_list_ptr->accept = COAP_CT_NONE;
|
||||
coap_msg_ptr->options_list_ptr->block2 = COAP_OPTION_BLOCK_NONE;
|
||||
coap_msg_ptr->options_list_ptr->block1 = COAP_OPTION_BLOCK_NONE;
|
||||
options_list_ptr->uri_port = COAP_OPTION_URI_PORT_NONE;
|
||||
options_list_ptr->observe = COAP_OBSERVE_NONE;
|
||||
options_list_ptr->accept = COAP_CT_NONE;
|
||||
options_list_ptr->block2 = COAP_OPTION_BLOCK_NONE;
|
||||
options_list_ptr->block1 = COAP_OPTION_BLOCK_NONE;
|
||||
|
||||
return coap_msg_ptr->options_list_ptr;
|
||||
return options_list_ptr;
|
||||
}
|
||||
|
||||
sn_coap_hdr_s *sn_coap_parser(struct coap_s *handle, uint16_t packet_data_len, uint8_t *packet_data_ptr, coap_version_e *coap_version_ptr)
|
||||
|
@ -156,43 +180,35 @@ void sn_coap_parser_release_allocated_coap_msg_mem(struct coap_s *handle, sn_coa
|
|||
}
|
||||
|
||||
if (freed_coap_msg_ptr != NULL) {
|
||||
if (freed_coap_msg_ptr->uri_path_ptr != NULL) {
|
||||
handle->sn_coap_protocol_free(freed_coap_msg_ptr->uri_path_ptr);
|
||||
|
||||
// As there are multiple sequential calls to the protocol_free, caching pointer to it
|
||||
// saves one instruction per call.
|
||||
void (*local_free)(void *) = handle->sn_coap_protocol_free;
|
||||
|
||||
local_free(freed_coap_msg_ptr->uri_path_ptr);
|
||||
local_free(freed_coap_msg_ptr->token_ptr);
|
||||
|
||||
// same here, caching the struct start saves a bit.
|
||||
sn_coap_options_list_s *options_list_ptr = freed_coap_msg_ptr->options_list_ptr;
|
||||
|
||||
if (options_list_ptr != NULL) {
|
||||
|
||||
local_free(options_list_ptr->proxy_uri_ptr);
|
||||
|
||||
local_free(options_list_ptr->etag_ptr);
|
||||
|
||||
local_free(options_list_ptr->uri_host_ptr);
|
||||
|
||||
local_free(options_list_ptr->location_path_ptr);
|
||||
|
||||
local_free(options_list_ptr->location_query_ptr);
|
||||
|
||||
local_free(options_list_ptr->uri_query_ptr);
|
||||
|
||||
local_free(options_list_ptr);
|
||||
}
|
||||
|
||||
if (freed_coap_msg_ptr->token_ptr != NULL) {
|
||||
handle->sn_coap_protocol_free(freed_coap_msg_ptr->token_ptr);
|
||||
}
|
||||
|
||||
if (freed_coap_msg_ptr->options_list_ptr != NULL) {
|
||||
if (freed_coap_msg_ptr->options_list_ptr->proxy_uri_ptr != NULL) {
|
||||
handle->sn_coap_protocol_free(freed_coap_msg_ptr->options_list_ptr->proxy_uri_ptr);
|
||||
}
|
||||
|
||||
if (freed_coap_msg_ptr->options_list_ptr->etag_ptr != NULL) {
|
||||
handle->sn_coap_protocol_free(freed_coap_msg_ptr->options_list_ptr->etag_ptr);
|
||||
}
|
||||
|
||||
if (freed_coap_msg_ptr->options_list_ptr->uri_host_ptr != NULL) {
|
||||
handle->sn_coap_protocol_free(freed_coap_msg_ptr->options_list_ptr->uri_host_ptr);
|
||||
}
|
||||
|
||||
if (freed_coap_msg_ptr->options_list_ptr->location_path_ptr != NULL) {
|
||||
handle->sn_coap_protocol_free(freed_coap_msg_ptr->options_list_ptr->location_path_ptr);
|
||||
}
|
||||
|
||||
if (freed_coap_msg_ptr->options_list_ptr->location_query_ptr != NULL) {
|
||||
handle->sn_coap_protocol_free(freed_coap_msg_ptr->options_list_ptr->location_query_ptr);
|
||||
}
|
||||
|
||||
if (freed_coap_msg_ptr->options_list_ptr->uri_query_ptr != NULL) {
|
||||
handle->sn_coap_protocol_free(freed_coap_msg_ptr->options_list_ptr->uri_query_ptr);
|
||||
}
|
||||
|
||||
handle->sn_coap_protocol_free(freed_coap_msg_ptr->options_list_ptr);
|
||||
}
|
||||
|
||||
handle->sn_coap_protocol_free(freed_coap_msg_ptr);
|
||||
local_free(freed_coap_msg_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,14 +285,13 @@ static int8_t sn_coap_parser_options_parse(struct coap_s *handle, uint8_t **pack
|
|||
return -1;
|
||||
}
|
||||
|
||||
dst_coap_msg_ptr->token_ptr = handle->sn_coap_protocol_malloc(dst_coap_msg_ptr->token_len);
|
||||
dst_coap_msg_ptr->token_ptr = sn_coap_protocol_malloc_copy(handle, *packet_data_pptr, dst_coap_msg_ptr->token_len);
|
||||
|
||||
if (dst_coap_msg_ptr->token_ptr == NULL) {
|
||||
tr_error("sn_coap_parser_options_parse - failed to allocate token!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(dst_coap_msg_ptr->token_ptr, *packet_data_pptr, dst_coap_msg_ptr->token_len);
|
||||
(*packet_data_pptr) += dst_coap_msg_ptr->token_len;
|
||||
}
|
||||
|
||||
|
@ -379,14 +394,13 @@ static int8_t sn_coap_parser_options_parse(struct coap_s *handle, uint8_t **pack
|
|||
dst_coap_msg_ptr->options_list_ptr->proxy_uri_len = option_len;
|
||||
(*packet_data_pptr)++;
|
||||
|
||||
dst_coap_msg_ptr->options_list_ptr->proxy_uri_ptr = handle->sn_coap_protocol_malloc(option_len);
|
||||
dst_coap_msg_ptr->options_list_ptr->proxy_uri_ptr = sn_coap_protocol_malloc_copy(handle, *packet_data_pptr, option_len);
|
||||
|
||||
if (dst_coap_msg_ptr->options_list_ptr->proxy_uri_ptr == NULL) {
|
||||
tr_error("sn_coap_parser_options_parse - COAP_OPTION_PROXY_URI allocation failed!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(dst_coap_msg_ptr->options_list_ptr->proxy_uri_ptr, *packet_data_pptr, option_len);
|
||||
(*packet_data_pptr) += option_len;
|
||||
|
||||
break;
|
||||
|
@ -415,13 +429,12 @@ static int8_t sn_coap_parser_options_parse(struct coap_s *handle, uint8_t **pack
|
|||
dst_coap_msg_ptr->options_list_ptr->uri_host_len = option_len;
|
||||
(*packet_data_pptr)++;
|
||||
|
||||
dst_coap_msg_ptr->options_list_ptr->uri_host_ptr = handle->sn_coap_protocol_malloc(option_len);
|
||||
dst_coap_msg_ptr->options_list_ptr->uri_host_ptr = sn_coap_protocol_malloc_copy(handle, *packet_data_pptr, option_len);
|
||||
|
||||
if (dst_coap_msg_ptr->options_list_ptr->uri_host_ptr == NULL) {
|
||||
tr_error("sn_coap_parser_options_parse - COAP_OPTION_URI_HOST allocation failed!");
|
||||
return -1;
|
||||
}
|
||||
memcpy(dst_coap_msg_ptr->options_list_ptr->uri_host_ptr, *packet_data_pptr, option_len);
|
||||
(*packet_data_pptr) += option_len;
|
||||
|
||||
break;
|
||||
|
@ -623,9 +636,9 @@ static int8_t sn_coap_parser_options_parse_multiple_options(struct coap_s *handl
|
|||
/* Uri-Query is modified to following format: temp1'\0'temp2'\0'temp3 i.e. */
|
||||
/* Uri-Path is modified to following format: temp1\temp2\temp3 i.e. */
|
||||
if (option == COAP_OPTION_URI_QUERY || option == COAP_OPTION_LOCATION_QUERY || option == COAP_OPTION_ETAG || option == COAP_OPTION_ACCEPT) {
|
||||
memset(temp_parsed_uri_query_ptr, '&', 1);
|
||||
*temp_parsed_uri_query_ptr = '&';
|
||||
} else if (option == COAP_OPTION_URI_PATH || option == COAP_OPTION_LOCATION_PATH) {
|
||||
memset(temp_parsed_uri_query_ptr, '/', 1);
|
||||
*temp_parsed_uri_query_ptr = '/';
|
||||
}
|
||||
|
||||
temp_parsed_uri_query_ptr++;
|
||||
|
@ -680,7 +693,7 @@ static int8_t sn_coap_parser_options_parse_multiple_options(struct coap_s *handl
|
|||
*
|
||||
* \param uint16_t option_number_len length of the first option part
|
||||
*/
|
||||
static int16_t sn_coap_parser_options_count_needed_memory_multiple_option(uint8_t *packet_data_ptr, uint16_t packet_left_len, sn_coap_option_numbers_e option, uint16_t option_number_len)
|
||||
static int16_t sn_coap_parser_options_count_needed_memory_multiple_option(const uint8_t *packet_data_ptr, uint16_t packet_left_len, sn_coap_option_numbers_e option, uint16_t option_number_len)
|
||||
{
|
||||
uint16_t ret_value = 0;
|
||||
uint16_t i = 1;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue