Skip to content

Commit de99c0f

Browse files
author
Cruz Monrreal
authored
Merge pull request #7160 from jarvte/ppp_lwip_disconnect_hangs
Fixed ppp_lwip_disconnect hangs when connection failure.
2 parents 02e90ef + b35dc6a commit de99c0f

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

features/FEATURE_LWIP/lwip-interface/ppp_lwip.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,19 +295,15 @@ 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;
298+
err_t ret = ERR_OK;
299+
if (ppp_active) {
300+
ret = ppp_close(my_ppp_pcb, 0);
301+
if (ret == ERR_OK) {
302+
/* close call made, now let's catch the response in the status callback */
303+
sys_arch_sem_wait(&ppp_close_sem, 0);
304+
}
305+
ppp_active = false;
301306
}
302-
303-
/* close call made, now let's catch the response in the status callback */
304-
sys_arch_sem_wait(&ppp_close_sem, 0);
305-
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;
310-
311307
return ret;
312308
}
313309

@@ -373,6 +369,9 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_event_t,
373369
retcode = lwip._add_ppp_interface(stream, true, stack, &my_interface);
374370
if (retcode != NSAPI_ERROR_OK) {
375371
my_interface = NULL;
372+
my_stream->set_blocking(true);
373+
my_stream = NULL;
374+
connection_status_cb = NULL;
376375
return retcode;
377376
}
378377
}
@@ -381,6 +380,13 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_event_t,
381380
// attach deferred until ppp_lwip_connect, called from mbed_lwip_bringup
382381
retcode = my_interface->bringup(false, NULL, NULL, NULL, stack, blocking_connect);
383382

383+
if (retcode != NSAPI_ERROR_OK) {
384+
connection_status_cb = NULL;
385+
my_stream->sigio(NULL);
386+
my_stream->set_blocking(true);
387+
my_stream = NULL;
388+
}
389+
384390
if (retcode != NSAPI_ERROR_OK && connect_error_code != NSAPI_ERROR_OK) {
385391
return connect_error_code;
386392
} else {
@@ -390,7 +396,19 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_event_t,
390396

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

396414
NetworkStack *nsapi_ppp_get_stack()

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,9 @@ nsapi_error_t AT_CellularNetwork::disconnect()
374374
nsapi_error_t err = nsapi_ppp_disconnect(_at.get_file_handle());
375375
// after ppp disconnect if we wan't to use same at handler we need to set filehandle again to athandler so it
376376
// will set the correct sigio and nonblocking
377-
if (err == NSAPI_ERROR_OK) {
378-
_at.lock();
379-
_at.set_file_handle(_at.get_file_handle());
380-
_at.unlock();
381-
}
377+
_at.lock();
378+
_at.set_file_handle(_at.get_file_handle());
379+
_at.unlock();
382380
return err;
383381
#else
384382
_at.lock();

0 commit comments

Comments
 (0)