@@ -338,7 +338,11 @@ static void ot_joiner_start_handler(otError error, void *context)
338
338
switch (error ) {
339
339
case OT_ERROR_NONE :
340
340
NET_INFO ("Join success" );
341
- otThreadSetEnabled (ot_context -> instance , true);
341
+ error = otThreadSetEnabled (ot_context -> instance , true);
342
+ if (error != OT_ERROR_NONE ) {
343
+ NET_ERR ("Failed to start the OpenThread network [%d]" , error );
344
+ }
345
+
342
346
break ;
343
347
default :
344
348
NET_ERR ("Join failed [%d]" , error );
@@ -439,7 +443,11 @@ int openthread_start(struct openthread_context *ot_context)
439
443
goto exit ;
440
444
}
441
445
442
- otIp6SetEnabled (ot_context -> instance , true);
446
+ error = otIp6SetEnabled (ot_context -> instance , true);
447
+ if (error != OT_ERROR_NONE ) {
448
+ NET_ERR ("Failed to set %s [%d]" , "IPv6 support" , error );
449
+ goto exit ;
450
+ }
443
451
444
452
/* Sleepy End Device specific configuration. */
445
453
if (IS_ENABLED (CONFIG_OPENTHREAD_MTD_SED )) {
@@ -450,8 +458,17 @@ int openthread_start(struct openthread_context *ot_context)
450
458
*/
451
459
ot_mode .mRxOnWhenIdle = false;
452
460
453
- otThreadSetLinkMode (ot_context -> instance , ot_mode );
454
- otLinkSetPollPeriod (ot_context -> instance , OT_POLL_PERIOD );
461
+ error = otThreadSetLinkMode (ot_context -> instance , ot_mode );
462
+ if (error != OT_ERROR_NONE ) {
463
+ NET_ERR ("Failed to set %s [%d]" , "link mode" , error );
464
+ goto exit ;
465
+ }
466
+
467
+ error = otLinkSetPollPeriod (ot_context -> instance , OT_POLL_PERIOD );
468
+ if (error != OT_ERROR_NONE ) {
469
+ NET_ERR ("Failed to set %s [%d]" , "poll period" , error );
470
+ goto exit ;
471
+ }
455
472
}
456
473
457
474
/* Configure Child Supervision and MLE Child timeouts. */
@@ -486,16 +503,39 @@ int openthread_start(struct openthread_context *ot_context)
486
503
otExtendedPanId xpanid ;
487
504
otNetworkKey networkKey ;
488
505
489
- otThreadSetNetworkName (ot_instance , OT_NETWORK_NAME );
490
- otLinkSetChannel (ot_instance , OT_CHANNEL );
491
- otLinkSetPanId (ot_instance , OT_PANID );
506
+ error = otThreadSetNetworkName (ot_instance , OT_NETWORK_NAME );
507
+ if (error != OT_ERROR_NONE ) {
508
+ NET_ERR ("Failed to set %s [%d]" , "network name" , error );
509
+ goto exit ;
510
+ }
511
+
512
+ error = otLinkSetChannel (ot_instance , OT_CHANNEL );
513
+ if (error != OT_ERROR_NONE ) {
514
+ NET_ERR ("Failed to set %s [%d]" , "channel" , error );
515
+ goto exit ;
516
+ }
517
+
518
+ error = otLinkSetPanId (ot_instance , OT_PANID );
519
+ if (error != OT_ERROR_NONE ) {
520
+ NET_ERR ("Failed to set %s [%d]" , "PAN ID" , error );
521
+ goto exit ;
522
+ }
523
+
492
524
net_bytes_from_str (xpanid .m8 , 8 , (char * )OT_XPANID );
493
- otThreadSetExtendedPanId (ot_instance , & xpanid );
525
+ error = otThreadSetExtendedPanId (ot_instance , & xpanid );
526
+ if (error != OT_ERROR_NONE ) {
527
+ NET_ERR ("Failed to set %s [%d]" , "ext PAN ID" , error );
528
+ goto exit ;
529
+ }
494
530
495
531
if (strlen (OT_NETWORKKEY )) {
496
532
net_bytes_from_str (networkKey .m8 , OT_NETWORK_KEY_SIZE ,
497
533
(char * )OT_NETWORKKEY );
498
- otThreadSetNetworkKey (ot_instance , & networkKey );
534
+ error = otThreadSetNetworkKey (ot_instance , & networkKey );
535
+ if (error != OT_ERROR_NONE ) {
536
+ NET_ERR ("Failed to set %s [%d]" , "network key" , error );
537
+ goto exit ;
538
+ }
499
539
}
500
540
}
501
541
@@ -542,7 +582,7 @@ static int openthread_init(struct net_if *iface)
542
582
.name = "openthread" ,
543
583
.no_yield = true,
544
584
};
545
- otError err ;
585
+ otError err = OT_ERROR_NONE ;
546
586
547
587
NET_DBG ("openthread_init" );
548
588
@@ -565,7 +605,11 @@ static int openthread_init(struct net_if *iface)
565
605
}
566
606
567
607
if (IS_ENABLED (CONFIG_OPENTHREAD_COPROCESSOR )) {
568
- otPlatUartEnable ();
608
+ err = otPlatUartEnable ();
609
+ if (err != OT_ERROR_NONE ) {
610
+ NET_ERR ("Failed to enable UART: [%d]" , err );
611
+ }
612
+
569
613
otNcpHdlcInit (ot_context -> instance , ncp_hdlc_send );
570
614
} else {
571
615
otIp6SetReceiveFilterEnabled (ot_context -> instance , true);
@@ -613,7 +657,7 @@ static int openthread_init(struct net_if *iface)
613
657
614
658
(void )k_work_submit_to_queue (& ot_context -> work_q , & ot_context -> api_work );
615
659
616
- return 0 ;
660
+ return ( err == OT_ERROR_NONE ) ? 0 : - EIO ;
617
661
}
618
662
619
663
void ieee802154_init (struct net_if * iface )
0 commit comments