ble_mesh: stack: Move bt_mesh_rand to mesh_common.c

This commit is contained in:
lly 2020-12-07 17:59:31 +08:00
parent a0da80fe89
commit 1cdd2b0609
6 changed files with 19 additions and 38 deletions

View File

@ -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

View File

@ -15,6 +15,8 @@
#include <string.h>
#include <errno.h>
#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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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) || \