diff --git a/features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp b/features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp index 4dbd4a8a7f..6280bf1a39 100644 --- a/features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp +++ b/features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp @@ -102,15 +102,20 @@ int InterfaceNanostack::disconnect() nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy) { - if (_phy) { + if (_phy && phy && _phy != phy) { error("Phy already set"); return NSAPI_ERROR_IS_CONNECTED; } - _phy = phy; - return NSAPI_ERROR_OK; + if (phy) { + _phy = phy; + } + if (_phy) { + return do_initialize(); + } else { + return NSAPI_ERROR_PARAMETER; + } } - void Nanostack::Interface::network_handler(mesh_connection_status_t status) { if ((status == MESH_CONNECTED || status == MESH_CONNECTED_LOCAL || @@ -148,7 +153,9 @@ nsapi_error_t Nanostack::Interface::register_phy() { NanostackLockGuard lock; - _device_id = interface_phy.phy_register(); + if (_device_id < 0) { + _device_id = interface_phy.phy_register(); + } if (_device_id < 0) { return NSAPI_ERROR_DEVICE_ERROR; } diff --git a/features/nanostack/mbed-mesh-api/source/ThreadInterface.cpp b/features/nanostack/mbed-mesh-api/source/ThreadInterface.cpp index a45c5ae1a6..1975dafe2f 100644 --- a/features/nanostack/mbed-mesh-api/source/ThreadInterface.cpp +++ b/features/nanostack/mbed-mesh-api/source/ThreadInterface.cpp @@ -213,6 +213,10 @@ void ThreadInterface::device_eui64_set(const uint8_t *eui64) void ThreadInterface::device_eui64_get(uint8_t *eui64) { + memset(eui64, 0, 8); + if (!get_interface()) { + return; + } get_interface()->device_eui64_get(eui64); } @@ -226,6 +230,9 @@ void Nanostack::ThreadInterface::device_eui64_get(uint8_t *eui64) { if (!eui64_set) { uint8_t eui64_buf[8]; + if (register_phy() < 0) { + return; + } get_phy().get_mac_address(eui64_buf); device_eui64_set(eui64_buf); }