From d64f04bc95845d7de3d8cfbfe885ead1b80f10da Mon Sep 17 00:00:00 2001 From: Chen Wen Date: Wed, 24 Jul 2019 13:26:38 +0800 Subject: [PATCH] feat(dhcp): add menuconfig for DHCP discover retransmission interval --- components/lwip/Kconfig | 7 +++++++ components/lwip/lwip/src/core/ipv4/dhcp.c | 9 +++++++++ components/lwip/port/esp8266/include/lwipopts.h | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index a215839e..b5ab8284 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -229,6 +229,13 @@ config LWIP_DHCPS_MAX_STATION_NUM After this number is exceeded, DHCP server removes of the oldest device from it's address pool, without notification. +config LWIP_DHCP_DISCOVER_RETRANSMISSION_INTERVAL + int "DHCP discover retransmission interval (milliseconds)" + default 250 # 4 * default retransmission interval + range 250 1000 + help + Set time interval of retransmissions of DHCP discover. + endmenu #DHCP menuconfig LWIP_AUTOIP diff --git a/components/lwip/lwip/src/core/ipv4/dhcp.c b/components/lwip/lwip/src/core/ipv4/dhcp.c index 7590b6bc..a916c2ea 100644 --- a/components/lwip/lwip/src/core/ipv4/dhcp.c +++ b/components/lwip/lwip/src/core/ipv4/dhcp.c @@ -1007,7 +1007,16 @@ dhcp_discover(struct netif *netif) autoip_start(netif); } #endif /* LWIP_DHCP_AUTOIP_COOP */ + +#if ESP_DHCP +/** + * Since for embedded devices it's not that hard to miss a discover packet, so lower + * the discover retry backoff time from (2,4,8,16,32,60,60)s to (500m,1,2,4,8,15,15)s. + */ + msecs = (dhcp->tries < 6 ? 1 << dhcp->tries : 60) * LWIP_DHCP_DISCOVER_RETRANSMISSION_INTERVAL; +#else msecs = (dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000; +#endif dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_discover(): set request timeout %"U16_F" msecs\n", msecs)); return result; diff --git a/components/lwip/port/esp8266/include/lwipopts.h b/components/lwip/port/esp8266/include/lwipopts.h index 30ffdf31..07db6ed5 100644 --- a/components/lwip/port/esp8266/include/lwipopts.h +++ b/components/lwip/port/esp8266/include/lwipopts.h @@ -54,6 +54,7 @@ #define ESP_LWIP 1 #define ESP_IP4_ATON 1 +#define ESP_DHCP 1 #ifdef CONFIG_ESP_DNS #define ESP_DNS 1 @@ -720,6 +721,14 @@ size_t memp_malloc_get_size(size_t type); * (up to the maximum limit defined here). */ #define LWIP_DHCP_MAX_DNS_SERVERS DNS_MAX_SERVERS + +/** + * LWIP_DHCP_DISCOVER_RETRANSMISSION_INTERVAL: DHCP discover retry backoff time. + * (default is 250, a conservative default, the maximum is 1000.) + * Since for embedded devices it's not that hard to miss a discover packet, so + * it is necessary to reduce the discovery retry backoff time. + */ +#define LWIP_DHCP_DISCOVER_RETRANSMISSION_INTERVAL CONFIG_LWIP_DHCP_DISCOVER_RETRANSMISSION_INTERVAL /** * @} */