diff --git a/features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h b/features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h index f157a598fc9..2a3b5a6faf9 100644 --- a/features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h +++ b/features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h @@ -63,6 +63,7 @@ class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed int8_t interface_id; int8_t _device_id; rtos::Semaphore connect_semaphore; + rtos::Semaphore disconnect_semaphore; mbed::Callback _connection_status_cb; nsapi_connection_status_t _connect_status; diff --git a/features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp b/features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp index c2df8c55670..a89d9c8b934 100644 --- a/features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp +++ b/features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp @@ -119,9 +119,13 @@ nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy) void Nanostack::Interface::network_handler(mesh_connection_status_t status) { - if ((status == MESH_CONNECTED || status == MESH_CONNECTED_LOCAL || - status == MESH_CONNECTED_GLOBAL) && _blocking) { - connect_semaphore.release(); + if (_blocking) { + if (status == MESH_CONNECTED || status == MESH_CONNECTED_LOCAL || + status == MESH_CONNECTED_GLOBAL) { + connect_semaphore.release(); + } else if (status == MESH_DISCONNECTED) { + disconnect_semaphore.release(); + } } diff --git a/features/nanostack/mbed-mesh-api/source/NanostackEthernetInterface.cpp b/features/nanostack/mbed-mesh-api/source/NanostackEthernetInterface.cpp index 04bca1b9a63..5c517f03cd7 100644 --- a/features/nanostack/mbed-mesh-api/source/NanostackEthernetInterface.cpp +++ b/features/nanostack/mbed-mesh-api/source/NanostackEthernetInterface.cpp @@ -84,7 +84,7 @@ nsapi_error_t Nanostack::EthernetInterface::bringup(bool dhcp, const char *ip, return NSAPI_ERROR_DHCP_FAILURE; // sort of... } } - return 0; + return NSAPI_ERROR_OK; } nsapi_error_t NanostackEthernetInterface::do_initialize() @@ -97,8 +97,26 @@ nsapi_error_t NanostackEthernetInterface::do_initialize() nsapi_error_t Nanostack::EthernetInterface::bringdown() { - if (enet_tasklet_disconnect(true)) { + nanostack_lock(); + int8_t status = enet_tasklet_disconnect(true); + nanostack_unlock(); + + if (status == -1) { + return NSAPI_ERROR_DEVICE_ERROR; + } else if (status == -2) { + return NSAPI_ERROR_NO_MEMORY; + } else if (status == -3) { + return NSAPI_ERROR_ALREADY; + } else if (status != 0) { return NSAPI_ERROR_DEVICE_ERROR; } + + if (_blocking) { + int32_t count = disconnect_semaphore.wait(30000); + + if (count <= 0) { + return NSAPI_ERROR_TIMEOUT; + } + } return NSAPI_ERROR_OK; }