One of the things I have been missing for a long time in lwipthread.c is a set of hooks that are called once the netif goes up/down. I use them e.g. to init/deinit SNTP.
To add them without impact on existing applications we can use weak symbols. Somewhere above lwip_thread add:
Code: Select all
/**
* Redefine this hook to execute custom logic when the lwip netif
* comes up
*/
__attribute__((weak)) void lwipNetifUpHook(struct netif* thisif) {
(void)thisif;
}
/**
* Redefine this hook to execute custom logic when the lwip netif
* goes down
*/
__attribute__((weak)) void lwipNetifDownHook(struct netif* thisif) {
(void)thisif;
}
and then replace the if(mask & PERIODIC_TIMER_ID) block with this (only 2 lines added where the code is called):
Code: Select all
if (mask & PERIODIC_TIMER_ID) {
bool current_link_status = macPollLinkStatus(ÐD1);
if (current_link_status != netif_is_link_up(&thisif)) {
if (current_link_status) { //Interface is coming up
lwipNetifUpHook(&thisif);
tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_up,
&thisif, 0);
#if LWIP_DHCP
dhcp_start(&thisif);
#endif
}
else { //Interface is going down
lwipNetifDownHook(&thisif);
tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_down,
&thisif, 0);
#if LWIP_DHCP
dhcp_stop(&thisif);
#endif
}
}
}
Besides solving the main issue of the hooks not being easily accessible without lwipthread.c modification, this also means that an application using it in an unmodified manner now has access to the netif object. I don't remember off my head what I used that for, but I think it was related with the DHCP server. I have described the older method of adding thisif to global scope on my blog: http://techoverflow.net/blog/2015/03/16/accessing-lwip-struct-netif-instance-in-chibios/
Best regards, Uli