Skip to content

Commit b5a9dae

Browse files
committed
TODO: fix in zephyr
Signed-off-by: Adrian Gielniewski <[email protected]>
1 parent 9fd9b0a commit b5a9dae

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

modules/openthread/openthread.c

+42-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <zephyr/logging/log.h>
1414
LOG_MODULE_REGISTER(net_openthread_platform, CONFIG_OPENTHREAD_PLATFORM_LOG_LEVEL);
1515

16+
#include <ctype.h>
17+
1618
#include <zephyr/kernel.h>
1719
#include <zephyr/init.h>
1820
#include <zephyr/version.h>
@@ -157,6 +159,28 @@ static void ot_joiner_start_handler(otError error, void *context)
157159
}
158160
}
159161

162+
static int bytes_from_str(uint8_t *buf, int buf_len, const char *src)
163+
{
164+
size_t i;
165+
size_t src_len = strlen(src);
166+
char *endptr;
167+
168+
for (i = 0U; i < src_len; i++) {
169+
if (!isxdigit((unsigned char)src[i]) && src[i] != ':') {
170+
return -EINVAL;
171+
}
172+
}
173+
174+
(void)memset(buf, 0, buf_len);
175+
176+
for (i = 0U; i < (size_t)buf_len; i++) {
177+
buf[i] = (uint8_t)strtol(src, &endptr, 16);
178+
src = ++endptr;
179+
}
180+
181+
return 0;
182+
}
183+
160184
static bool ot_setup_default_configuration(void)
161185
{
162186
otExtendedPanId xpanid = {0};
@@ -181,15 +205,15 @@ static bool ot_setup_default_configuration(void)
181205
return false;
182206
}
183207

184-
net_bytes_from_str(xpanid.m8, 8, (char *)OT_XPANID);
208+
bytes_from_str(xpanid.m8, 8, (char *)OT_XPANID);
185209
error = otThreadSetExtendedPanId(openthread_instance, &xpanid);
186210
if (error != OT_ERROR_NONE) {
187211
LOG_ERR("Failed to set %s [%d]", "ext PAN ID", error);
188212
return false;
189213
}
190214

191215
if (strlen(OT_NETWORKKEY)) {
192-
net_bytes_from_str(networkKey.m8, OT_NETWORK_KEY_SIZE, (char *)OT_NETWORKKEY);
216+
bytes_from_str(networkKey.m8, OT_NETWORK_KEY_SIZE, (char *)OT_NETWORKKEY);
193217
error = otThreadSetNetworkKey(openthread_instance, &networkKey);
194218
if (error != OT_ERROR_NONE) {
195219
LOG_ERR("Failed to set %s [%d]", "network key", error);
@@ -483,5 +507,20 @@ void openthread_mutex_unlock(void)
483507
}
484508

485509
#ifdef CONFIG_OPENTHREAD_SYS_INIT
486-
SYS_INIT(openthread_init, POST_KERNEL, CONFIG_OPENTHREAD_SYS_INIT_PRIORITY);
510+
static int openthread_sys_init(void)
511+
{
512+
int error;
513+
514+
error = openthread_init();
515+
516+
if (error == 0) {
517+
#ifndef CONFIG_OPENTHREAD_MANUAL_START
518+
error = openthread_run();
519+
#endif
520+
}
521+
522+
return error;
523+
}
524+
525+
SYS_INIT(openthread_sys_init, POST_KERNEL, CONFIG_OPENTHREAD_SYS_INIT_PRIORITY);
487526
#endif /* CONFIG_OPENTHREAD_SYS_INIT */

0 commit comments

Comments
 (0)