Skip to content

Commit 8bd9772

Browse files
author
Cruz Monrreal
authored
Merge pull request #8975 from KariHaapalehto/fix_valid_mac_address
Initialize the interface at the construction
2 parents ce1929b + f7de4a4 commit 8bd9772

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

features/nanostack/mbed-mesh-api/source/LoWPANNDInterface.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,19 @@ bool LoWPANNDInterface::getRouterIpAddress(char *address, int8_t len)
178178
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == LOWPAN && DEVICE_802_15_4_PHY
179179
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()
180180
{
181-
static LoWPANNDInterface lowpan(&NanostackRfPhy::get_default_instance());
182-
183-
return &lowpan;
181+
static bool inited;
182+
static LoWPANNDInterface interface;
183+
singleton_lock();
184+
if (!inited) {
185+
nsapi_error_t result = interface.initialize(&NanostackRfPhy::get_default_instance());
186+
if (result != 0) {
187+
tr_error("LoWPANND initialize failed: %d", error);
188+
singleton_unlock();
189+
return NULL;
190+
}
191+
inited = true;
192+
}
193+
singleton_unlock();
194+
return &interface;
184195
}
185196
#endif

features/nanostack/mbed-mesh-api/source/ThreadInterface.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,22 @@ mesh_error_t Nanostack::ThreadInterface::device_pskd_set(const char *pskd)
269269

270270
#define THREAD 0x2345
271271
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == THREAD && DEVICE_802_15_4_PHY
272+
272273
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()
273274
{
274-
static ThreadInterface thread(&NanostackRfPhy::get_default_instance());
275-
276-
return &thread;
275+
static bool inited;
276+
static ThreadInterface interface;
277+
singleton_lock();
278+
if (!inited) {
279+
nsapi_error_t result = interface.initialize(&NanostackRfPhy::get_default_instance());
280+
if (result != 0) {
281+
tr_error("Thread initialize failed: %d", error);
282+
singleton_unlock();
283+
return NULL;
284+
}
285+
inited = true;
286+
}
287+
singleton_unlock();
288+
return &interface;
277289
}
278290
#endif

features/nanostack/mbed-mesh-api/source/WisunInterface.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,19 @@ bool WisunInterface::getRouterIpAddress(char *address, int8_t len)
178178
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY
179179
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()
180180
{
181-
static WisunInterface wisun(&NanostackRfPhy::get_default_instance());
182-
183-
return &wisun;
181+
static bool inited;
182+
static WisunInterface interface;
183+
singleton_lock();
184+
if (!inited) {
185+
nsapi_error_t result = interface.initialize(&NanostackRfPhy::get_default_instance());
186+
if (result != 0) {
187+
tr_error("Wi-SUN initialize failed: %d", error);
188+
singleton_unlock();
189+
return NULL;
190+
}
191+
inited = true;
192+
}
193+
singleton_unlock();
194+
return &interface;
184195
}
185196
#endif

0 commit comments

Comments
 (0)