zephyr/subsys/net/lib/openthread/platform/entropy.c
Kumar Gala 43a7d26603 drivers: entropy: replace CONFIG_ENTROPY_NAME with DT macro
Replace CONFIG_ENTROPY_NAME with DT_CHOSEN_ZEPHYR_ENTROPY_LABEL.  We now
set zephyr,entropy in the chosen node of the device tree to the entropy
device.

This allows us to remove CONFIG_ENTROPY_NAME from dts_fixup.h.  Also
remove any other stale ENTROPY related defines in dts_fixup.h files.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-13 09:14:21 -05:00

48 lines
1.0 KiB
C

/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <string.h>
#include <drivers/entropy.h>
#include <logging/log.h>
#include <openthread/platform/entropy.h>
#include "platform-zephyr.h"
LOG_MODULE_REGISTER(net_otPlat_entropy, CONFIG_OPENTHREAD_L2_LOG_LEVEL);
#if !defined(CONFIG_ENTROPY_HAS_DRIVER)
#error OpenThread requires an entropy source for a TRNG
#endif
otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
{
/* static to obtain it once in a first call */
static struct device *dev;
int err;
if ((aOutput == NULL) || (aOutputLength == 0)) {
return OT_ERROR_INVALID_ARGS;
}
if (dev == NULL) {
dev = device_get_binding(DT_CHOSEN_ZEPHYR_ENTROPY_LABEL);
if (dev == NULL) {
LOG_ERR("Failed to obtain entropy device");
return OT_ERROR_FAILED;
}
}
err = entropy_get_entropy(dev, aOutput, aOutputLength);
if (err != 0) {
LOG_ERR("Failed to obtain entropy, err %d", err);
return OT_ERROR_FAILED;
}
return OT_ERROR_NONE;
}