@@ -295,19 +295,15 @@ extern "C" err_t ppp_lwip_connect(void *pcb)
295
295
296
296
extern " C" err_t ppp_lwip_disconnect (void *pcb)
297
297
{
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 ;
301
306
}
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
-
311
307
return ret;
312
308
}
313
309
@@ -373,6 +369,9 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_event_t,
373
369
retcode = lwip._add_ppp_interface (stream, true , stack, &my_interface);
374
370
if (retcode != NSAPI_ERROR_OK) {
375
371
my_interface = NULL ;
372
+ my_stream->set_blocking (true );
373
+ my_stream = NULL ;
374
+ connection_status_cb = NULL ;
376
375
return retcode;
377
376
}
378
377
}
@@ -381,6 +380,13 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_event_t,
381
380
// attach deferred until ppp_lwip_connect, called from mbed_lwip_bringup
382
381
retcode = my_interface->bringup (false , NULL , NULL , NULL , stack, blocking_connect);
383
382
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
+
384
390
if (retcode != NSAPI_ERROR_OK && connect_error_code != NSAPI_ERROR_OK) {
385
391
return connect_error_code;
386
392
} else {
@@ -390,7 +396,19 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_event_t,
390
396
391
397
nsapi_error_t nsapi_ppp_disconnect (FileHandle *stream)
392
398
{
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;
394
412
}
395
413
396
414
NetworkStack *nsapi_ppp_get_stack ()
0 commit comments