@@ -329,7 +329,11 @@ static void ot_joiner_start_handler(otError error, void *context)
329
329
switch (error ) {
330
330
case OT_ERROR_NONE :
331
331
NET_INFO ("Join success" );
332
- otThreadSetEnabled (ot_context -> instance , true);
332
+ error = otThreadSetEnabled (ot_context -> instance , true);
333
+ if (error != OT_ERROR_NONE ) {
334
+ NET_ERR ("Failed to start the OpenThread network [%d]" , error );
335
+ }
336
+
333
337
break ;
334
338
default :
335
339
NET_ERR ("Join failed [%d]" , error );
@@ -430,7 +434,11 @@ int openthread_start(struct openthread_context *ot_context)
430
434
goto exit ;
431
435
}
432
436
433
- otIp6SetEnabled (ot_context -> instance , true);
437
+ error = otIp6SetEnabled (ot_context -> instance , true);
438
+ if (error != OT_ERROR_NONE ) {
439
+ NET_ERR ("Failed to set %s [%d]" , "IPv6 support" , error );
440
+ goto exit ;
441
+ }
434
442
435
443
/* Sleepy End Device specific configuration. */
436
444
if (IS_ENABLED (CONFIG_OPENTHREAD_MTD_SED )) {
@@ -441,8 +449,17 @@ int openthread_start(struct openthread_context *ot_context)
441
449
*/
442
450
ot_mode .mRxOnWhenIdle = false;
443
451
444
- otThreadSetLinkMode (ot_context -> instance , ot_mode );
445
- otLinkSetPollPeriod (ot_context -> instance , OT_POLL_PERIOD );
452
+ error = otThreadSetLinkMode (ot_context -> instance , ot_mode );
453
+ if (error != OT_ERROR_NONE ) {
454
+ NET_ERR ("Failed to set %s [%d]" , "link mode" , error );
455
+ goto exit ;
456
+ }
457
+
458
+ error = otLinkSetPollPeriod (ot_context -> instance , OT_POLL_PERIOD );
459
+ if (error != OT_ERROR_NONE ) {
460
+ NET_ERR ("Failed to set %s [%d]" , "poll period" , error );
461
+ goto exit ;
462
+ }
446
463
}
447
464
448
465
/* Configure Child Supervision and MLE Child timeouts. */
@@ -477,16 +494,39 @@ int openthread_start(struct openthread_context *ot_context)
477
494
otExtendedPanId xpanid ;
478
495
otNetworkKey networkKey ;
479
496
480
- otThreadSetNetworkName (ot_instance , OT_NETWORK_NAME );
481
- otLinkSetChannel (ot_instance , OT_CHANNEL );
482
- otLinkSetPanId (ot_instance , OT_PANID );
497
+ error = otThreadSetNetworkName (ot_instance , OT_NETWORK_NAME );
498
+ if (error != OT_ERROR_NONE ) {
499
+ NET_ERR ("Failed to set %s [%d]" , "network name" , error );
500
+ goto exit ;
501
+ }
502
+
503
+ error = otLinkSetChannel (ot_instance , OT_CHANNEL );
504
+ if (error != OT_ERROR_NONE ) {
505
+ NET_ERR ("Failed to set %s [%d]" , "channel" , error );
506
+ goto exit ;
507
+ }
508
+
509
+ error = otLinkSetPanId (ot_instance , OT_PANID );
510
+ if (error != OT_ERROR_NONE ) {
511
+ NET_ERR ("Failed to set %s [%d]" , "PAN ID" , error );
512
+ goto exit ;
513
+ }
514
+
483
515
net_bytes_from_str (xpanid .m8 , 8 , (char * )OT_XPANID );
484
- otThreadSetExtendedPanId (ot_instance , & xpanid );
516
+ error = otThreadSetExtendedPanId (ot_instance , & xpanid );
517
+ if (error != OT_ERROR_NONE ) {
518
+ NET_ERR ("Failed to set %s [%d]" , "ext PAN ID" , error );
519
+ goto exit ;
520
+ }
485
521
486
522
if (strlen (OT_NETWORKKEY )) {
487
523
net_bytes_from_str (networkKey .m8 , OT_NETWORK_KEY_SIZE ,
488
524
(char * )OT_NETWORKKEY );
489
- otThreadSetNetworkKey (ot_instance , & networkKey );
525
+ error = otThreadSetNetworkKey (ot_instance , & networkKey );
526
+ if (error != OT_ERROR_NONE ) {
527
+ NET_ERR ("Failed to set %s [%d]" , "network key" , error );
528
+ goto exit ;
529
+ }
490
530
}
491
531
}
492
532
@@ -533,7 +573,7 @@ static int openthread_init(struct net_if *iface)
533
573
.name = "openthread" ,
534
574
.no_yield = true,
535
575
};
536
- otError err ;
576
+ otError err = OT_ERROR_NONE ;
537
577
538
578
NET_DBG ("openthread_init" );
539
579
@@ -556,7 +596,11 @@ static int openthread_init(struct net_if *iface)
556
596
}
557
597
558
598
if (IS_ENABLED (CONFIG_OPENTHREAD_COPROCESSOR )) {
559
- otPlatUartEnable ();
599
+ err = otPlatUartEnable ();
600
+ if (err != OT_ERROR_NONE ) {
601
+ NET_ERR ("Failed to enable UART: [%d]" , err );
602
+ }
603
+
560
604
otNcpHdlcInit (ot_context -> instance , ncp_hdlc_send );
561
605
} else {
562
606
otIp6SetReceiveFilterEnabled (ot_context -> instance , true);
@@ -604,7 +648,7 @@ static int openthread_init(struct net_if *iface)
604
648
605
649
(void )k_work_submit_to_queue (& ot_context -> work_q , & ot_context -> api_work );
606
650
607
- return 0 ;
651
+ return ( err == OT_ERROR_NONE ) ? 0 : - EIO ;
608
652
}
609
653
610
654
void ieee802154_init (struct net_if * iface )
0 commit comments