@@ -295,20 +295,18 @@ 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;
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
+ }
305
303
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
+ }
310
308
311
- return ret ;
309
+ return ERR_OK ;
312
310
}
313
311
314
312
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,
373
371
retcode = lwip._add_ppp_interface (stream, true , stack, &my_interface);
374
372
if (retcode != NSAPI_ERROR_OK) {
375
373
my_interface = NULL ;
374
+ my_stream->set_blocking (true );
375
+ my_stream = NULL ;
376
+ connection_status_cb = NULL ;
376
377
return retcode;
377
378
}
378
379
}
@@ -381,6 +382,12 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_event_t,
381
382
// attach deferred until ppp_lwip_connect, called from mbed_lwip_bringup
382
383
retcode = my_interface->bringup (false , NULL , NULL , NULL , stack, blocking_connect);
383
384
385
+ if (retcode != NSAPI_ERROR_OK) {
386
+ connection_status_cb = NULL ;
387
+ my_stream->set_blocking (true );
388
+ my_stream = NULL ;
389
+ }
390
+
384
391
if (retcode != NSAPI_ERROR_OK && connect_error_code != NSAPI_ERROR_OK) {
385
392
return connect_error_code;
386
393
} else {
@@ -390,7 +397,19 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_event_t,
390
397
391
398
nsapi_error_t nsapi_ppp_disconnect (FileHandle *stream)
392
399
{
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;
394
413
}
395
414
396
415
NetworkStack *nsapi_ppp_get_stack ()
0 commit comments