diff --git a/components/bt/esp_ble_mesh/mesh_common/include/mesh_common.h b/components/bt/esp_ble_mesh/mesh_common/include/mesh_common.h index 746ec0f2ce..e39b73dff8 100644 --- a/components/bt/esp_ble_mesh/mesh_common/include/mesh_common.h +++ b/components/bt/esp_ble_mesh/mesh_common/include/mesh_common.h @@ -73,6 +73,8 @@ void bt_mesh_free_buf(struct net_buf_simple *buf); */ uint8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send); +int bt_mesh_rand(void *buf, size_t len); + #ifdef __cplusplus } #endif diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_common.c b/components/bt/esp_ble_mesh/mesh_common/mesh_common.c index 4eeb3280a4..3f0be4bb4a 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_common.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_common.c @@ -15,6 +15,8 @@ #include #include +#include "esp_system.h" + #include "mesh_main.h" #include "client_common.h" #include "mesh_common.h" @@ -96,3 +98,17 @@ uint8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send) return client->msg_role; } + +int bt_mesh_rand(void *buf, size_t len) +{ + if (buf == NULL || len == 0) { + BT_ERR("%s, Invalid parameter", __func__); + return -EINVAL; + } + + esp_fill_random(buf, len); + + BT_DBG("Random %s", bt_hex(buf, len)); + + return 0; +} diff --git a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c index 17a43e7934..dc1c19b139 100644 --- a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c @@ -1797,24 +1797,6 @@ void bt_mesh_adapt_init(void) bt_mesh_rand(bt_mesh_private_key, sizeof(bt_mesh_private_key)); } -int bt_mesh_rand(void *buf, size_t len) -{ - int i; - - if (buf == NULL || len == 0) { - BT_ERR("%s, Invalid parameter", __func__); - return -EAGAIN; - } - - for (i = 0; i < (int)(len / sizeof(uint32_t)); i++) { - uint32_t rand = esp_random(); - memcpy(buf + i * sizeof(uint32_t), &rand, sizeof(uint32_t)); - } - - BT_DBG("Rand %s", bt_hex(buf, len)); - return 0; -} - void bt_mesh_set_private_key(const uint8_t pri_key[32]) { memcpy(bt_mesh_private_key, pri_key, 32); diff --git a/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h b/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h index fb1d5c2bdf..cc3d2b7bfc 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h @@ -767,8 +767,6 @@ void bt_mesh_gatt_deinit(void); void bt_mesh_adapt_init(void); -int bt_mesh_rand(void *buf, size_t len); - void bt_mesh_set_private_key(const uint8_t pri_key[32]); const uint8_t *bt_mesh_pub_key_get(void); diff --git a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c index c4363c7433..80389ce792 100644 --- a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c @@ -1758,24 +1758,6 @@ void bt_mesh_adapt_init(void) bt_mesh_rand(bt_mesh_private_key, sizeof(bt_mesh_private_key)); } -int bt_mesh_rand(void *buf, size_t len) -{ - int i; - - if (buf == NULL || len == 0) { - BT_ERR("%s, Invalid parameter", __func__); - return -EAGAIN; - } - - for (i = 0; i < (int)(len / sizeof(uint32_t)); i++) { - uint32_t rand = esp_random(); - memcpy(buf + i * sizeof(uint32_t), &rand, sizeof(uint32_t)); - } - - BT_DBG("Rand %s", bt_hex(buf, len)); - return 0; -} - void bt_mesh_set_private_key(const uint8_t pri_key[32]) { memcpy(bt_mesh_private_key, pri_key, 32); diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy_server.c b/components/bt/esp_ble_mesh/mesh_core/proxy_server.c index b5374686ec..4d84c9a5b8 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy_server.c +++ b/components/bt/esp_ble_mesh/mesh_core/proxy_server.c @@ -16,6 +16,7 @@ #include "access.h" #include "transport.h" #include "foundation.h" +#include "mesh_common.h" #include "proxy_server.h" #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \