zephyr/subsys/net/lib/openthread/platform/random.c
Kamil Sroka 83b2218ab5 subsys: net: lib: Add OpenThread platform
OpenThread requires platform definition with standarized API
so we have to add wrappers to make it compatible with Zephyr.
OpenThread is based on autoconf, this requires
more specific CMakeLists.txt which allows to clone specific
commit or point to local copy of openthread.

Signed-off-by: Kamil Sroka <kamil.sroka@nordicsemi.no>
2018-01-29 22:42:03 -05:00

38 lines
686 B
C

/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <string.h>
#include <openthread/types.h>
#include <openthread/platform/random.h>
#include "platform-zephyr.h"
uint32_t otPlatRandomGet(void)
{
return sys_rand32_get();
}
otError otPlatRandomGetTrue(u8_t *aOutput, u16_t aOutputLength)
{
int i;
u32_t random;
if (!aOutput) {
return OT_ERROR_INVALID_ARGS;
}
for (i = 0; i < (aOutputLength & 0xFFFC); i += 4) {
random = sys_rand32_get();
memcpy(&aOutput[i], &random, sizeof(random));
}
random = sys_rand32_get();
memcpy(&aOutput[i], &random, aOutputLength & 0x0003);
return OT_ERROR_NONE;
}