Skip to content

Commit b2aefec

Browse files
committed
Merge pull request #215 from ARMmbed/ns_init
Adjust Nanostack startup
2 parents 31cea1b + 51d3fc0 commit b2aefec

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

net/nanostack-interface/NanostackInterface.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
#include "ns_address.h"
2222
#include "nsdynmemLIB.h"
2323
#include "eventOS_scheduler.h"
24+
#include "randLIB.h"
2425

2526
#include "mbed-mesh-api/MeshInterfaceFactory.h"
2627

28+
#include "mesh_system.h" // from inside mbed-mesh-api
2729
#include "socket_api.h"
2830
#include "driverRFPhy.h"
2931
#include "net_interface.h"
@@ -481,8 +483,6 @@ int NanostackInterface::register_rf()
481483

482484
int NanostackInterface::actual_connect()
483485
{
484-
nanostack_lock();
485-
486486
mesh_error_t status = get_mesh_api()->connect();
487487
if (status != MESH_ERROR_NONE) {
488488
nanostack_unlock();
@@ -512,6 +512,8 @@ int NanostackInterface::disconnect()
512512

513513
int ThreadInterface::connect()
514514
{
515+
// initialize mesh networking resources, memory, timers, etc...
516+
mesh_system_init();
515517
nanostack_lock();
516518

517519
mesh_api = MeshInterfaceFactory::createInterface(MESH_TYPE_THREAD);
@@ -523,6 +525,10 @@ int ThreadInterface::connect()
523525
nanostack_unlock();
524526
return NSAPI_ERROR_DEVICE_ERROR;
525527
}
528+
529+
// After the RF is up, we can seed the random from it.
530+
randLIB_seed_random();
531+
526532
mesh_error_t status = ((MeshThread *)mesh_api)->init(rf_device_id, AbstractMesh::mesh_network_handler_t(static_cast<NanostackInterface *>(this), &ThreadInterface::mesh_network_handler), eui64, NULL);
527533
if (status != MESH_ERROR_NONE) {
528534
nanostack_unlock();
@@ -537,6 +543,8 @@ int ThreadInterface::connect()
537543

538544
int LoWPANNDInterface::connect()
539545
{
546+
// initialize mesh networking resources, memory, timers, etc...
547+
mesh_system_init();
540548
nanostack_lock();
541549

542550
mesh_api = MeshInterfaceFactory::createInterface(MESH_TYPE_6LOWPAN_ND);
@@ -548,6 +556,10 @@ int LoWPANNDInterface::connect()
548556
nanostack_unlock();
549557
return NSAPI_ERROR_DEVICE_ERROR;
550558
}
559+
560+
// After the RF is up, we can seed the random from it.
561+
randLIB_seed_random();
562+
551563
mesh_error_t status = ((Mesh6LoWPAN_ND *)mesh_api)->init(rf_device_id, AbstractMesh::mesh_network_handler_t(static_cast<NanostackInterface *>(this), &LoWPANNDInterface::mesh_network_handler));
552564
if (status != MESH_ERROR_NONE) {
553565
nanostack_unlock();

0 commit comments

Comments
 (0)