diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index d44f876f02..21c5334f6b 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -247,6 +247,14 @@ menu "LWIP" server. Last valid DHCP configuration is stored in nvs and restored after reset/power-up. If IP is still available, there is no need for sending discovery message to DHCP server and save some time. + config LWIP_DHCP_COARSE_TIMER_SECS + int "DHCP coarse timer interval(s)" + default 1 + range 1 10 + help + Set DHCP coarse interval in seconds. + A higher value will be less precise but cost less power consumption. + menu "DHCP server" config LWIP_DHCPS diff --git a/components/lwip/lwip b/components/lwip/lwip index 6fa02bd30d..a7abf28e02 160000 --- a/components/lwip/lwip +++ b/components/lwip/lwip @@ -1 +1 @@ -Subproject commit 6fa02bd30daa656f896c7a36248253fb3b97660d +Subproject commit a7abf28e02282b32479f4bbaf2d90f09d2a60f4c diff --git a/components/lwip/port/esp32/include/lwipopts.h b/components/lwip/port/esp32/include/lwipopts.h index 329690bda4..ad5a9114b0 100644 --- a/components/lwip/port/esp32/include/lwipopts.h +++ b/components/lwip/port/esp32/include/lwipopts.h @@ -44,6 +44,11 @@ #include "netif/dhcp_state.h" #include "sntp/sntp_get_set_time.h" +#ifdef __cplusplus +extern "C" +{ +#endif + /* Enable all Espressif-only options */ /* @@ -262,6 +267,25 @@ (uint16_t)(1 * 1000) : \ (uint16_t)(((tries) < 6 ? 1 << (tries) : 60) * 250)) +#define DHCP_COARSE_TIMER_SECS CONFIG_LWIP_DHCP_COARSE_TIMER_SECS + +static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min) +{ + uint32_t timeout = lease; + if (timeout == 0) { + timeout = min; + } + timeout = (timeout + DHCP_COARSE_TIMER_SECS - 1) / DHCP_COARSE_TIMER_SECS; + return timeout; +} + +#define DHCP_CALC_TIMEOUT_FROM_OFFERED_T0_LEASE(dhcp) \ + timeout_from_offered((dhcp)->offered_t0_lease, 120) +#define DHCP_CALC_TIMEOUT_FROM_OFFERED_T1_RENEW(dhcp) \ + timeout_from_offered((dhcp)->offered_t1_renew, (dhcp)->t0_timeout >> 1 /* 50% */) +#define DHCP_CALC_TIMEOUT_FROM_OFFERED_T2_REBIND(dhcp) \ + timeout_from_offered((dhcp)->offered_t2_rebind, ((dhcp)->t0_timeout / 8) * 7 /* 87.5% */) + /** * CONFIG_LWIP_DHCP_RESTORE_LAST_IP==1: Last valid IP address obtained from DHCP server * is restored after reset/power-up. @@ -1074,4 +1098,8 @@ #define SOC_SEND_LOG //printf +#ifdef __cplusplus +} +#endif + #endif /* __LWIPOPTS_H__ */