From dab4215a9a447de8c69d670964c964f8897753b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Thu, 7 Jun 2018 12:47:01 +0300 Subject: [PATCH] Fixed ppp disconnect hangs when connection failure. --- .../FEATURE_LWIP/lwip-interface/ppp_lwip.cpp | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/features/FEATURE_LWIP/lwip-interface/ppp_lwip.cpp b/features/FEATURE_LWIP/lwip-interface/ppp_lwip.cpp index c05e6c9e9e..6989073112 100644 --- a/features/FEATURE_LWIP/lwip-interface/ppp_lwip.cpp +++ b/features/FEATURE_LWIP/lwip-interface/ppp_lwip.cpp @@ -295,20 +295,18 @@ extern "C" err_t ppp_lwip_connect(void *pcb) extern "C" err_t ppp_lwip_disconnect(void *pcb) { - err_t ret = ppp_close(my_ppp_pcb, 0); - if (ret != ERR_OK) { - return ret; + if (ppp_active) { + err_t ret = ppp_close(my_ppp_pcb, 0); + if (ret != ERR_OK) { + return ret; + } + + /* close call made, now let's catch the response in the status callback */ + sys_arch_sem_wait(&ppp_close_sem, 0); + ppp_active = false; } - /* close call made, now let's catch the response in the status callback */ - sys_arch_sem_wait(&ppp_close_sem, 0); - - /* Detach callbacks, and put handle back to default blocking mode */ - my_stream->sigio(Callback()); - my_stream->set_blocking(true); - my_stream = NULL; - - return ret; + return ERR_OK; } extern "C" nsapi_error_t ppp_lwip_if_init(void *pcb, struct netif *netif, const nsapi_ip_stack_t stack) @@ -373,6 +371,9 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callbackset_blocking(true); + my_stream = NULL; + connection_status_cb = NULL; return retcode; } } @@ -381,6 +382,12 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callbackbringup(false, NULL, NULL, NULL, stack, blocking_connect); + if (retcode != NSAPI_ERROR_OK) { + connection_status_cb = NULL; + my_stream->set_blocking(true); + my_stream = NULL; + } + if (retcode != NSAPI_ERROR_OK && connect_error_code != NSAPI_ERROR_OK) { return connect_error_code; } else { @@ -390,7 +397,19 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callbackbringdown(); + if (my_stream != stream) { + return NSAPI_ERROR_NO_CONNECTION; + } + + nsapi_error_t retcode = my_interface->bringdown(); + + connection_status_cb = NULL; + /* Detach callbacks, and put handle back to default blocking mode */ + my_stream->sigio(NULL); + my_stream->set_blocking(true); + my_stream = NULL; + + return retcode; } NetworkStack *nsapi_ppp_get_stack()