13
13
#include <zephyr/logging/log.h>
14
14
LOG_MODULE_REGISTER (net_openthread_platform , CONFIG_OPENTHREAD_PLATFORM_LOG_LEVEL );
15
15
16
+ #include <ctype.h>
17
+
16
18
#include <zephyr/kernel.h>
17
19
#include <zephyr/init.h>
18
20
#include <zephyr/version.h>
@@ -157,6 +159,28 @@ static void ot_joiner_start_handler(otError error, void *context)
157
159
}
158
160
}
159
161
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
+
160
184
static bool ot_setup_default_configuration (void )
161
185
{
162
186
otExtendedPanId xpanid = {0 };
@@ -181,15 +205,15 @@ static bool ot_setup_default_configuration(void)
181
205
return false;
182
206
}
183
207
184
- net_bytes_from_str (xpanid .m8 , 8 , (char * )OT_XPANID );
208
+ bytes_from_str (xpanid .m8 , 8 , (char * )OT_XPANID );
185
209
error = otThreadSetExtendedPanId (openthread_instance , & xpanid );
186
210
if (error != OT_ERROR_NONE ) {
187
211
LOG_ERR ("Failed to set %s [%d]" , "ext PAN ID" , error );
188
212
return false;
189
213
}
190
214
191
215
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 );
193
217
error = otThreadSetNetworkKey (openthread_instance , & networkKey );
194
218
if (error != OT_ERROR_NONE ) {
195
219
LOG_ERR ("Failed to set %s [%d]" , "network key" , error );
@@ -483,5 +507,20 @@ void openthread_mutex_unlock(void)
483
507
}
484
508
485
509
#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 );
487
526
#endif /* CONFIG_OPENTHREAD_SYS_INIT */
0 commit comments