From 58a4c3985ae5a276ae9c33078db11746ed00f28f Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 12 Jul 2019 17:25:51 +0200 Subject: [PATCH] mesh: generate random device uuid on start --- src/mesh/mesh_node.c | 2 +- test/mesh/mesh_access.c | 23 ++++++++++++++++++++--- test/mesh/mesh_proxy.c | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/mesh/mesh_node.c b/src/mesh/mesh_node.c index c395d404a..48aef9992 100644 --- a/src/mesh/mesh_node.c +++ b/src/mesh/mesh_node.c @@ -117,7 +117,7 @@ mesh_element_t * mesh_element_iterator_next(mesh_element_iterator_t * iterator){ } void mesh_node_set_device_uuid(const uint8_t * device_uuid){ - memcpy(mesh_node_get_device_uuid, device_uuid, 16); + memcpy(mesh_node_device_uuid, device_uuid, 16); mesh_node_have_device_uuid = 1; } diff --git a/test/mesh/mesh_access.c b/test/mesh/mesh_access.c index cd40e9151..ded79e865 100644 --- a/test/mesh/mesh_access.c +++ b/test/mesh/mesh_access.c @@ -1738,14 +1738,31 @@ void mesh_access_setup_from_provisioning_data(const mesh_provisioning_data_t * p #endif } -void mesh_access_setup_without_provisiong_data(void){ - const uint8_t * device_uuid = mesh_node_get_device_uuid(); +static btstack_crypto_random_t mesh_access_crypto_random; + +static uint8_t random_device_uuid[16]; + +static void mesh_access_setup_unprovisioned_device(void * arg){ + // set random value + if (arg == NULL){ + mesh_node_set_device_uuid(random_device_uuid); + } + #ifdef ENABLE_MESH_PB_ADV // PB-ADV - beacon_unprovisioned_device_start(device_uuid, 0); + beacon_unprovisioned_device_start(mesh_node_get_device_uuid(), 0); #endif #ifdef ENABLE_MESH_PB_GATT mesh_proxy_start_advertising_unprovisioned_device(); #endif } +void mesh_access_setup_without_provisiong_data(void){ + const uint8_t * device_uuid = mesh_node_get_device_uuid(); + if (device_uuid){ + mesh_access_setup_unprovisioned_device((void *)device_uuid); + } else{ + btstack_crypto_random_generate(&mesh_access_crypto_random, random_device_uuid, 16, &mesh_access_setup_unprovisioned_device, NULL); + } +} + diff --git a/test/mesh/mesh_proxy.c b/test/mesh/mesh_proxy.c index 92e0df347..31622f400 100644 --- a/test/mesh/mesh_proxy.c +++ b/test/mesh/mesh_proxy.c @@ -43,6 +43,7 @@ #include "mesh/gatt_bearer.h" #include "mesh/mesh_crypto.h" #include "mesh/mesh_network.h" +#include "mesh/mesh_node.h" #include "mesh/mesh_lower_transport.h" #include "bluetooth_company_id.h" #include "bluetooth_data_types.h"