mesh: extract mesh_peer from mesh_transport

This commit is contained in:
Matthias Ringwald 2019-04-03 13:57:45 +02:00
parent 14476d0514
commit 257edf9b97
5 changed files with 109 additions and 47 deletions

View File

@ -27,7 +27,7 @@ file(GLOB SOURCES_LIBUSB "../../platform/libusb/*.c")
file(GLOB SOURCES_OFF "../../src/ble/le_device_db_memory.c" "../../src/ble/le_device_db_tlv.c") file(GLOB SOURCES_OFF "../../src/ble/le_device_db_memory.c" "../../src/ble/le_device_db_tlv.c")
list(REMOVE_ITEM SOURCES_BLE ${SOURCES_OFF}) list(REMOVE_ITEM SOURCES_BLE ${SOURCES_OFF})
set(SOURCES_MESH_NEW main.c mesh_transport.c provisioner.c provisioning.c provisioning_device.c provisioning_provisioner.c) set(SOURCES_MESH_NEW main.c mesh_transport.c mesh_peer.c provisioner.c provisioning.c provisioning_device.c provisioning_provisioner.c)
set(SOURCES set(SOURCES
${SOURCES_POSIX} ${SOURCES_POSIX}

View File

@ -46,13 +46,13 @@ LDFLAGS += $(shell pkg-config libusb-1.0 --libs)
LDFLAGS += -lCppUTest -lCppUTestExt LDFLAGS += -lCppUTest -lCppUTestExt
mesh: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_OBJ} pb_adv.o pb_gatt.o mesh_proxy_service_server.o mesh_provisioning_service_server.o mesh_crypto.o provisioning_device.o mesh_network.o mesh_transport.o mesh.o mesh: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_OBJ} pb_adv.o pb_gatt.o mesh_proxy_service_server.o mesh_provisioning_service_server.o mesh_crypto.o provisioning_device.o mesh_network.o mesh_peer.o mesh_transport.o mesh.o
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
provisioner: ${CORE_OBJ} ${COMMON_OBJ} ${SM_OBJ} pb_adv.o mesh_crypto.o provisioning_provisioner.o provisioner.o provisioner: ${CORE_OBJ} ${COMMON_OBJ} ${SM_OBJ} pb_adv.o mesh_crypto.o provisioning_provisioner.o provisioner.o
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
mesh_message_test: mesh_message_test.c mesh_network.o mesh_transport.o mesh_crypto.o btstack_memory.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_message_test.c mesh_network.o mesh_peer.o mesh_transport.o mesh_crypto.o btstack_memory.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 $@ g++ $^ ${CFLAGS} ${LDFLAGS} -o $@
sniffer: ${CORE_OBJ} ${COMMON_OBJ} ${SM_OBJ} sniffer.c sniffer: ${CORE_OBJ} ${COMMON_OBJ} ${SM_OBJ} sniffer.c
@ -73,7 +73,7 @@ mesh_provisioning_device: mesh_provisioning_device.h ${CORE_OBJ} ${COMMON_OBJ} $
mesh_proxy_server.h: mesh_proxy_server.gatt mesh_proxy_server.h: mesh_proxy_server.gatt
python ${BTSTACK_ROOT}/tool/compile_gatt.py $< $@ python ${BTSTACK_ROOT}/tool/compile_gatt.py $< $@
mesh_proxy_server: mesh_proxy_server.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_OBJ} mesh_transport.o mesh_network.o mesh_crypto.o gatt_bearer.c mesh_proxy_service_server.o mesh_proxy_server.o mesh_proxy_server: mesh_proxy_server.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_OBJ} mesh_peer.o mesh_transport.o mesh_network.o mesh_crypto.o gatt_bearer.c mesh_proxy_service_server.o mesh_proxy_server.o
${CC} $(filter-out mesh_proxy_server.h,$^) ${CFLAGS} ${LDFLAGS} -o $@ ${CC} $(filter-out mesh_proxy_server.h,$^) ${CFLAGS} ${LDFLAGS} -o $@
EXAMPLES = mesh provisioner mesh_message_test sniffer provisioning_device_test provisioning_provisioner_test mesh_provisioning_device mesh_proxy_server EXAMPLES = mesh provisioner mesh_message_test sniffer provisioning_device_test provisioning_provisioner_test mesh_provisioning_device mesh_proxy_server

40
test/mesh/mesh_peer.c Normal file
View File

@ -0,0 +1,40 @@
//
// Created by Matthias Ringwald on 2019-04-03.
//
#include "btstack_memory.h"
#include "btstack_util.h"
#include "mesh_transport.h"
#include "ble/mesh/beacon.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "mesh_peer.h"
#define MESH_NUM_PEERS 5
static mesh_peer_t mesh_peers[MESH_NUM_PEERS];
void mesh_seq_auth_reset(void){
int i;
for(i=0;i<MESH_NUM_PEERS;i++){
memset(&mesh_peers[i], 0, sizeof(mesh_peer_t));
}
}
mesh_peer_t * mesh_peer_for_addr(uint16_t address){
int i;
for (i=0;i<MESH_NUM_PEERS;i++){
if (mesh_peers[i].address == address){
return &mesh_peers[i];
}
}
for (i=0;i<MESH_NUM_PEERS;i++){
if (mesh_peers[i].address== MESH_ADDRESS_UNSASSIGNED){
memset(&mesh_peers[i], 0, sizeof(mesh_peer_t));
mesh_peers[i].address = address;
return &mesh_peers[i];
}
}
return NULL;
}

64
test/mesh/mesh_peer.h Normal file
View File

@ -0,0 +1,64 @@
/*
* Copyright (C) 2018 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_PEER_H
#define __MESH_PEER_H
#include "ble/mesh/mesh_network.h"
// mesh seq auth validation
typedef struct {
// primary element address
uint16_t address;
// next expected seq number
uint32_t seq;
// segmented transport message
mesh_transport_pdu_t * transport_pdu;
// seq_zero
uint16_t seq_zero;
// block ack
uint32_t block_ack;
} mesh_peer_t;
// get peer info for address
mesh_peer_t * mesh_peer_for_addr(uint16_t address);
// reset seq auth == replay protection
void mesh_seq_auth_reset();
#endif //__MESH_PEER_H

View File

@ -44,6 +44,7 @@
#include "mesh_transport.h" #include "mesh_transport.h"
#include "btstack_util.h" #include "btstack_util.h"
#include "btstack_memory.h" #include "btstack_memory.h"
#include "mesh_peer.h"
static uint16_t primary_element_address; static uint16_t primary_element_address;
@ -192,49 +193,6 @@ static uint8_t mesh_network_send(uint16_t netkey_index, uint8_t ctl, uint8_t ttl
return 0; return 0;
} }
// mesh seq auth validation
typedef struct {
// primary element address
uint16_t address;
// next expected seq number
uint32_t seq;
// segmented transport message
mesh_transport_pdu_t * transport_pdu;
// seq_zero
uint16_t seq_zero;
// block ack
uint32_t block_ack;
} mesh_peer_t;
#define MESH_NUM_PEERS 5
static mesh_peer_t mesh_peers[MESH_NUM_PEERS];
static mesh_peer_t * mesh_peer_for_addr(uint16_t address){
int i;
for (i=0;i<MESH_NUM_PEERS;i++){
if (mesh_peers[i].address == address){
return &mesh_peers[i];
}
}
for (i=0;i<MESH_NUM_PEERS;i++){
if (mesh_peers[i].address== MESH_ADDRESS_UNSASSIGNED){
memset(&mesh_peers[i], 0, sizeof(mesh_peer_t));
mesh_peers[i].address = address;
return &mesh_peers[i];
}
}
return NULL;
}
void mesh_seq_auth_reset(void){
int i;
for(i=0;i<MESH_NUM_PEERS;i++){
memset(&mesh_peers[i], 0, sizeof(mesh_peer_t));
}
}
// stub lower transport // stub lower transport
static void mesh_lower_transport_run(void); static void mesh_lower_transport_run(void);