Skip to content

Commit e8654cd

Browse files
authored
Consistent netif->status_callback (#62)
Call our own netif_status_changed from netif->status_callback() as it should have been from the beginning. Using esp8266/Arduino mDNS example, where * AP is started first * mDNS is started * STA is started later Without this change, status callback is called only for STA, once, when IP address is not assigned With this change, status callback is called when AP or STA change their state, including when an IP address is later set by DHCP
1 parent 06164fb commit e8654cd

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

glue-lwip/lwip-git.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ static void netif_sta_status_callback (struct netif* netif)
347347
if (netif_default == netif)
348348
netif_set_default(NULL);
349349
}
350+
351+
netif_status_changed(netif);
350352
}
351353

352354
static void netif_init_common (struct netif* netif)
@@ -389,7 +391,7 @@ static err_t netif_init_ap (struct netif* netif)
389391

390392
netif->name[0] = 'a';
391393
netif->name[1] = 'p';
392-
netif->status_callback = NULL; // esp-netif-ap is made up by esp
394+
netif->status_callback = netif_status_changed;
393395

394396
netif_init_common(netif);
395397

@@ -503,19 +505,26 @@ void esp2glue_netif_set_up1down0 (int netif_idx, int up1_or_down0)
503505
struct netif* netif = &netif_git[netif_idx];
504506
if (up1_or_down0)
505507
{
508+
// netif is brought UP
509+
506510
netif_set_link_up(netif);
507-
//netif_set_up(netif); // unwanted call to netif_sta_status_callback()
511+
512+
// We are called more often that it should by FW at boot time,
513+
// there is no need to uselessly shake the network interface:
514+
// netif_set_up(netif); <-- unwanted call to netif_sta_status_callback()
508515
netif->flags |= NETIF_FLAG_UP;
509516
#if ARDUINO
510-
if (!netif_enabled[netif_idx])
517+
//if (!netif_enabled[netif_idx])
511518
{
512519
netif_enabled[netif_idx] = 1;
513-
netif_status_changed(netif);
520+
//netif_status_changed(netif) was here but is now called from lwIP by netif->status_callback()
514521
}
515522
#endif
516523
}
517524
else
518525
{
526+
// netif is pulled DOWN
527+
519528
// stop dhcp client (if started)
520529
dhcp_release_and_stop(netif);
521530

@@ -532,10 +541,10 @@ void esp2glue_netif_set_up1down0 (int netif_idx, int up1_or_down0)
532541
if (netif_default == &netif_git[netif_idx])
533542
netif_set_default(NULL);
534543
#if ARDUINO
535-
if (netif_enabled[netif_idx])
544+
//if (netif_enabled[netif_idx])
536545
{
537546
netif_enabled[netif_idx] = 0;
538-
netif_status_changed(netif);
547+
//netif_status_changed(netif) was here but is now called from lwIP by netif->status_callback()
539548
}
540549
#endif
541550
}

0 commit comments

Comments
 (0)