From 04875b115d1a86b19091344a2404f537bc05d3cb Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 10 Jul 2019 12:32:34 +0200 Subject: [PATCH] mesh: move sequence number to mesh_iv_index_seq_number --- src/mesh/mesh_lower_transport.c | 13 +------ src/mesh/mesh_lower_transport.h | 4 -- src/mesh/mesh_upper_transport.c | 1 + test/mesh/Makefile | 3 +- test/mesh/mesh_iv_index_seq_number.c | 55 ++++++++++++++++++++++++++ test/mesh/mesh_iv_index_seq_number.h | 58 ++++++++++++++++++++++++++++ test/mesh/mesh_message_test.c | 1 + 7 files changed, 118 insertions(+), 17 deletions(-) create mode 100644 test/mesh/mesh_iv_index_seq_number.c create mode 100644 test/mesh/mesh_iv_index_seq_number.h diff --git a/src/mesh/mesh_lower_transport.c b/src/mesh/mesh_lower_transport.c index 111e0a9fe..094b5228e 100644 --- a/src/mesh/mesh_lower_transport.c +++ b/src/mesh/mesh_lower_transport.c @@ -45,6 +45,7 @@ #include "btstack_memory.h" #include "mesh_peer.h" #include "mesh_lower_transport.h" +#include "mesh_iv_index_seq_number.h" static uint16_t primary_element_address; static void (*higher_layer_handler)( mesh_transport_callback_type_t callback_type, mesh_transport_status_t status, mesh_pdu_t * pdu); @@ -670,18 +671,6 @@ static void mesh_lower_transport_run(void){ } } -uint32_t mesh_lower_transport_next_seq(void){ - return lower_transport_seq++; -} - -uint32_t mesh_lower_transport_peek_seq(void){ - return lower_transport_seq; -} - -void mesh_lower_transport_set_seq(uint32_t seq){ - lower_transport_seq = seq; -} - static void mesh_lower_transport_dump_network_pdus(const char *name, btstack_linked_list_t *list){ printf("List: %s:\n", name); btstack_linked_list_iterator_t it; diff --git a/src/mesh/mesh_lower_transport.h b/src/mesh/mesh_lower_transport.h index a269aac74..3915d918d 100644 --- a/src/mesh/mesh_lower_transport.h +++ b/src/mesh/mesh_lower_transport.h @@ -97,10 +97,6 @@ void mesh_lower_transport_init(); void mesh_lower_transport_set_primary_element_address(uint16_t unicast_address); void mesh_lower_transport_set_higher_layer_handler(void (*pdu_handler)( mesh_transport_callback_type_t callback_type, mesh_transport_status_t status, mesh_pdu_t * pdu)); -void mesh_lower_transport_set_seq(uint32_t seq); -uint32_t mesh_lower_transport_next_seq(void);; -uint32_t mesh_lower_transport_peek_seq(void); - void mesh_lower_transport_message_processed_by_higher_layer(mesh_pdu_t * pdu); void mesh_lower_transport_send_pdu(mesh_pdu_t * pdu); diff --git a/src/mesh/mesh_upper_transport.c b/src/mesh/mesh_upper_transport.c index 82a9cc84c..fe85fb1ba 100644 --- a/src/mesh/mesh_upper_transport.c +++ b/src/mesh/mesh_upper_transport.c @@ -48,6 +48,7 @@ #include "mesh_peer.h" #include "mesh_keys.h" #include "mesh_virtual_addresses.h" +#include "mesh_iv_index_seq_number.h" static uint16_t primary_element_address; diff --git a/test/mesh/Makefile b/test/mesh/Makefile index 3197816e1..e6be08324 100644 --- a/test/mesh/Makefile +++ b/test/mesh/Makefile @@ -18,6 +18,7 @@ CORE += \ hci_transport_h2_libusb.c \ hci_transport_h4.c \ btstack_tlv_posix.c \ + mesh_iv_index_seq_number.c \ le_device_db_fs.c \ l2cap.c \ uECC.c \ @@ -59,7 +60,7 @@ mesh: mesh.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_OBJ} p provisioner: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${SM_OBJ} pb_adv.o mesh_crypto.o provisioning_provisioner.o mesh_keys.o mesh_foundation.o mesh_network.o provisioner.o ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ -mesh_message_test: mesh_foundation.o mesh_message_test.c mesh_network.o mesh_peer.o mesh_lower_transport.o mesh_upper_transport.o mesh_virtual_addresses.o mesh_keys.o mesh_crypto.o btstack_memory.o btstack_memory_pool.o btstack_util.o btstack_crypto.o btstack_linked_list.o hci_dump.o uECC.o mock.o rijndael.o hci_cmd.o +mesh_message_test: mesh_foundation.o mesh_message_test.c mesh_iv_index_seq_number.o mesh_network.o mesh_peer.o mesh_lower_transport.o mesh_upper_transport.o mesh_virtual_addresses.o mesh_keys.o mesh_crypto.o btstack_memory.o btstack_memory_pool.o btstack_util.o btstack_crypto.o btstack_linked_list.o hci_dump.o uECC.o mock.o rijndael.o hci_cmd.o g++ $^ ${CFLAGS} ${LDFLAGS} -o $@ sniffer: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${SM_OBJ} mesh_keys.o mesh_network.o mesh_foundation.o sniffer.c diff --git a/test/mesh/mesh_iv_index_seq_number.c b/test/mesh/mesh_iv_index_seq_number.c new file mode 100644 index 000000000..dd78dbc6a --- /dev/null +++ b/test/mesh/mesh_iv_index_seq_number.c @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2014 BlueKitchen GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at + * contact@bluekitchen-gmbh.com + * + */ + +#define __BTSTACK_FILE__ "mesh_iv_index_seq_number.c" + +#include "mesh_iv_index_seq_number.h" + +static uint32_t lower_transport_seq; + +uint32_t mesh_lower_transport_next_seq(void){ + return lower_transport_seq++; +} + +uint32_t mesh_lower_transport_peek_seq(void){ + return lower_transport_seq; +} + +void mesh_lower_transport_set_seq(uint32_t seq){ + lower_transport_seq = seq; +} + diff --git a/test/mesh/mesh_iv_index_seq_number.h b/test/mesh/mesh_iv_index_seq_number.h new file mode 100644 index 000000000..e8dd7b5a8 --- /dev/null +++ b/test/mesh/mesh_iv_index_seq_number.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2019 BlueKitchen GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at + * contact@bluekitchen-gmbh.com + * + */ + +#ifndef __MESH_IV_INDEX_SEQ_NUMBER_H +#define __MESH_IV_INDEX_SEQ_NUMBER_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include + +void mesh_lower_transport_set_seq(uint32_t seq); +uint32_t mesh_lower_transport_next_seq(void);; +uint32_t mesh_lower_transport_peek_seq(void); + +#ifdef __cplusplus +} /* end of extern "C" */ +#endif + +#endif diff --git a/test/mesh/mesh_message_test.c b/test/mesh/mesh_message_test.c index 5f3fa8765..5009451df 100644 --- a/test/mesh/mesh_message_test.c +++ b/test/mesh/mesh_message_test.c @@ -16,6 +16,7 @@ #include "btstack_util.h" #include "provisioning.h" #include "btstack_memory.h" +#include "mesh_iv_index_seq_number.h" extern "C" int mock_process_hci_cmd(void);