Skip to content

Commit dab4215

Browse files
author
Teppo Järvelin
committed
Fixed ppp disconnect hangs when connection failure.
1 parent 4fcaa56 commit dab4215

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

features/FEATURE_LWIP/lwip-interface/ppp_lwip.cpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,20 +295,18 @@ extern "C" err_t ppp_lwip_connect(void *pcb)
295295

296296
extern "C" err_t ppp_lwip_disconnect(void *pcb)
297297
{
298-
err_t ret = ppp_close(my_ppp_pcb, 0);
299-
if (ret != ERR_OK) {
300-
return ret;
301-
}
302-
303-
/* close call made, now let's catch the response in the status callback */
304-
sys_arch_sem_wait(&ppp_close_sem, 0);
298+
if (ppp_active) {
299+
err_t ret = ppp_close(my_ppp_pcb, 0);
300+
if (ret != ERR_OK) {
301+
return ret;
302+
}
305303

306-
/* Detach callbacks, and put handle back to default blocking mode */
307-
my_stream->sigio(Callback<void()>());
308-
my_stream->set_blocking(true);
309-
my_stream = NULL;
304+
/* close call made, now let's catch the response in the status callback */
305+
sys_arch_sem_wait(&ppp_close_sem, 0);
306+
ppp_active = false;
307+
}
310308

311-
return ret;
309+
return ERR_OK;
312310
}
313311

314312
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, Callback<void(nsapi_event_t,
373371
retcode = lwip._add_ppp_interface(stream, true, stack, &my_interface);
374372
if (retcode != NSAPI_ERROR_OK) {
375373
my_interface = NULL;
374+
my_stream->set_blocking(true);
375+
my_stream = NULL;
376+
connection_status_cb = NULL;
376377
return retcode;
377378
}
378379
}
@@ -381,6 +382,12 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_event_t,
381382
// attach deferred until ppp_lwip_connect, called from mbed_lwip_bringup
382383
retcode = my_interface->bringup(false, NULL, NULL, NULL, stack, blocking_connect);
383384

385+
if (retcode != NSAPI_ERROR_OK) {
386+
connection_status_cb = NULL;
387+
my_stream->set_blocking(true);
388+
my_stream = NULL;
389+
}
390+
384391
if (retcode != NSAPI_ERROR_OK && connect_error_code != NSAPI_ERROR_OK) {
385392
return connect_error_code;
386393
} else {
@@ -390,7 +397,19 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_event_t,
390397

391398
nsapi_error_t nsapi_ppp_disconnect(FileHandle *stream)
392399
{
393-
return my_interface->bringdown();
400+
if (my_stream != stream) {
401+
return NSAPI_ERROR_NO_CONNECTION;
402+
}
403+
404+
nsapi_error_t retcode = my_interface->bringdown();
405+
406+
connection_status_cb = NULL;
407+
/* Detach callbacks, and put handle back to default blocking mode */
408+
my_stream->sigio(NULL);
409+
my_stream->set_blocking(true);
410+
my_stream = NULL;
411+
412+
return retcode;
394413
}
395414

396415
NetworkStack *nsapi_ppp_get_stack()

0 commit comments

Comments
 (0)