From 9efa7aca08046bf370a77c55fde9f12f0602723b Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Sun, 29 Mar 2020 21:32:35 +0200 Subject: [PATCH] mesh: extend mesh_upper_transport_pdu_free to handle mesh_upper_transport_pdus --- src/mesh/mesh_access.c | 11 +---------- src/mesh/mesh_access.h | 2 -- src/mesh/mesh_upper_transport.c | 13 +++++++++++++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/mesh/mesh_access.c b/src/mesh/mesh_access.c index 4034c740b..31e71dc99 100644 --- a/src/mesh/mesh_access.c +++ b/src/mesh/mesh_access.c @@ -617,15 +617,6 @@ static int mesh_access_setup_opcode(uint8_t * buffer, uint32_t opcode){ // mesh_message_t builder -void mesh_access_message_free(mesh_upper_transport_pdu_t * upper) { - btstack_assert(upper != NULL); - while (upper->segments) { - mesh_network_pdu_t *segment = (mesh_network_pdu_t *) btstack_linked_list_pop(&upper->segments); - mesh_network_pdu_free(segment); - } - btstack_memory_mesh_upper_transport_pdu_free(upper); -} - // returns true if successful bool mesh_access_message_add_data(mesh_upper_transport_pdu_t * pdu, const uint8_t * data, uint16_t data_len){ uint16_t bytes_current_segment = 0; @@ -759,7 +750,7 @@ mesh_upper_transport_pdu_t * mesh_access_setup_message(const mesh_access_message if (ok == false){ // memory alloc failed - mesh_access_message_free(upper_pdu); + mesh_upper_transport_pdu_free((mesh_pdu_t *) upper_pdu); upper_pdu = NULL; } diff --git a/src/mesh/mesh_access.h b/src/mesh/mesh_access.h index 80dde7131..e08432ac2 100644 --- a/src/mesh/mesh_access.h +++ b/src/mesh/mesh_access.h @@ -247,8 +247,6 @@ uint32_t mesh_access_parser_get_sig_model_identifier(mesh_access_parser_state_t uint32_t mesh_access_parser_get_vendor_model_identifier(mesh_access_parser_state_t * parser); uint32_t mesh_access_parser_get_model_identifier(mesh_access_parser_state_t * parser); -// message builder -void mesh_access_message_free(mesh_upper_transport_pdu_t * upper); mesh_upper_transport_pdu_t * mesh_access_message_init(uint32_t opcode); bool mesh_access_message_add_data(mesh_upper_transport_pdu_t * pdu, const uint8_t * data, uint16_t data_len); bool mesh_access_message_add_uint8(mesh_upper_transport_pdu_t * pdu, uint8_t value); diff --git a/src/mesh/mesh_upper_transport.c b/src/mesh/mesh_upper_transport.c index 681a07d58..37dba4183 100644 --- a/src/mesh/mesh_upper_transport.c +++ b/src/mesh/mesh_upper_transport.c @@ -965,9 +965,12 @@ static void mesh_upper_transport_pdu_handler(mesh_transport_callback_type_t call } void mesh_upper_transport_pdu_free(mesh_pdu_t * pdu){ + btstack_assert(pdu != NULL); mesh_network_pdu_t * network_pdu; mesh_segmented_pdu_t * message_pdu; + mesh_upper_transport_pdu_t * upper_pdu; switch (pdu->pdu_type) { + case MESH_PDU_TYPE_UPPER_UNSEGMENTED_CONTROL: case MESH_PDU_TYPE_NETWORK: network_pdu = (mesh_network_pdu_t *) pdu; mesh_network_pdu_free(network_pdu); @@ -975,6 +978,16 @@ void mesh_upper_transport_pdu_free(mesh_pdu_t * pdu){ case MESH_PDU_TYPE_SEGMENTED: message_pdu = (mesh_segmented_pdu_t *) pdu; mesh_message_pdu_free(message_pdu); + case MESH_PDU_TYPE_UPPER_UNSEGMENTED_ACCESS: + case MESH_PDU_TYPE_UPPER_SEGMENTED_ACCESS: + case MESH_PDU_TYPE_UPPER_SEGMENTED_CONTROL: + upper_pdu = (mesh_upper_transport_pdu_t *) pdu; + while (upper_pdu->segments) { + mesh_network_pdu_t *segment = (mesh_network_pdu_t *) btstack_linked_list_pop(&upper_pdu->segments); + mesh_network_pdu_free(segment); + } + btstack_memory_mesh_upper_transport_pdu_free(upper_pdu); + break; default: btstack_assert(false); break;