If CONFIG_OPENTHREAD_SYS_INIT is enabled, OpenThread initialisation should also consider running OpenThread automatically if CONFIG_OPENTHREAD_MANUAL_START is disabled. Removed also dependency on the `net_bytes_from_str` functions from the openthread.h file. Now, in the OpenThread module, there is an additional `openthread_utils.c/.h` file that can implement useful utilities for the OpenThread platform. Currently, it implements the `bytes_from_str` function to use it instead of `net_bytes_from_str`. Signed-off-by: Arkadiusz Balys <arkadiusz.balys@nordicsemi.no>
46 lines
759 B
C
46 lines
759 B
C
/*
|
|
* Copyright (c) 2025 Nordic Semiconductor ASA
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @file
|
|
* This file provides utility functions for the OpenThread module.
|
|
*
|
|
*/
|
|
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
|
|
#include <openthread_utils.h>
|
|
|
|
int bytes_from_str(uint8_t *buf, int buf_len, const char *src)
|
|
{
|
|
if (!buf || !src) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
size_t i;
|
|
size_t src_len = strlen(src);
|
|
char *endptr;
|
|
|
|
for (i = 0U; i < src_len; i++) {
|
|
if (!isxdigit((unsigned char)src[i]) && src[i] != ':') {
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
(void)memset(buf, 0, buf_len);
|
|
|
|
for (i = 0U; i < (size_t)buf_len; i++) {
|
|
buf[i] = (uint8_t)strtol(src, &endptr, 16);
|
|
src = ++endptr;
|
|
}
|
|
|
|
return 0;
|
|
}
|