diff --git a/src/esp8266/sdk_lwip/include/lwip/def.h b/src/esp8266/sdk_lwip/include/lwip/def.h index 9b6de6a..2bbfcac 100644 --- a/src/esp8266/sdk_lwip/include/lwip/def.h +++ b/src/esp8266/sdk_lwip/include/lwip/def.h @@ -43,6 +43,9 @@ extern "C" { #define LWIP_MAX(x , y) (((x) > (y)) ? (x) : (y)) #define LWIP_MIN(x , y) (((x) < (y)) ? (x) : (y)) +/* Get the number of entries in an array ('x' must NOT be a pointer!) */ +#define LWIP_ARRAYSIZE(x) (sizeof(x)/sizeof((x)[0])) + #ifndef NULL #define NULL ((void *)0) #endif diff --git a/src/esp8266/sdk_lwip/include/lwip/dhcp.h b/src/esp8266/sdk_lwip/include/lwip/dhcp.h index 57baab3..f4a6ae4 100644 --- a/src/esp8266/sdk_lwip/include/lwip/dhcp.h +++ b/src/esp8266/sdk_lwip/include/lwip/dhcp.h @@ -205,12 +205,13 @@ void dhcp_fine_tmr(void); #define DHCP_OPTION_PAD 0 #define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */ #define DHCP_OPTION_ROUTER 3 -#define DHCP_OPTION_DNS_SERVER 6 +#define DHCP_OPTION_DNS_SERVER 6 #define DHCP_OPTION_HOSTNAME 12 #define DHCP_OPTION_IP_TTL 23 #define DHCP_OPTION_MTU 26 #define DHCP_OPTION_BROADCAST 28 #define DHCP_OPTION_TCP_TTL 37 +#define DHCP_OPTION_NTP 42 #define DHCP_OPTION_END 255 /**add options for support more router by liuHan**/ diff --git a/src/esp8266/sdk_lwip/src/core/dhcp.c b/src/esp8266/sdk_lwip/src/core/dhcp.c index 91c3393..1df0e3f 100755 --- a/src/esp8266/sdk_lwip/src/core/dhcp.c +++ b/src/esp8266/sdk_lwip/src/core/dhcp.c @@ -132,6 +132,14 @@ u32_t dhcp_rx_options_val[DHCP_OPTION_IDX_MAX]; @todo: move this into struct dhcp? */ u8_t dhcp_rx_options_given[DHCP_OPTION_IDX_MAX]; +static const u8_t dhcp_discover_request_options[] = { + DHCP_OPTION_SUBNET_MASK, + DHCP_OPTION_ROUTER, + DHCP_OPTION_BROADCAST, + DHCP_OPTION_DNS_SERVER, + DHCP_OPTION_NTP, +}; + #define dhcp_option_given(dhcp, idx) (dhcp_rx_options_given[idx] != 0) #define dhcp_got_option(dhcp, idx) (dhcp_rx_options_given[idx] = 1) #define dhcp_clear_option(dhcp, idx) (dhcp_rx_options_given[idx] = 0) @@ -314,19 +322,10 @@ dhcp_select(struct netif *netif) dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4); dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->server_ip_addr))); - dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 12/*num options*/); - dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK); - dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER); - dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST); - dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER); - dhcp_option_byte(dhcp, DHCP_OPTION_DOMAIN_NAME); - dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINS); - dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINT); - dhcp_option_byte(dhcp, DHCP_OPTION_NB_TIS); - dhcp_option_byte(dhcp, DHCP_OPTION_PRD); - dhcp_option_byte(dhcp, DHCP_OPTION_STATIC_ROUTER); - dhcp_option_byte(dhcp, DHCP_OPTION_CLASSLESS_STATIC_ROUTER); - dhcp_option_byte(dhcp, DHCP_OPTION_VSN); + dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options)); + for (u8_t i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) { + dhcp_option_byte(dhcp, dhcp_discover_request_options[i]); + } #if LWIP_NETIF_HOSTNAME if (netif->hostname != NULL) { @@ -963,19 +962,10 @@ dhcp_discover(struct netif *netif) } } - dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 12/*num options*/); - dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK); - dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER); - dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST); - dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER); - dhcp_option_byte(dhcp, DHCP_OPTION_DOMAIN_NAME); - dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINS); - dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINT); - dhcp_option_byte(dhcp, DHCP_OPTION_NB_TIS); - dhcp_option_byte(dhcp, DHCP_OPTION_PRD); - dhcp_option_byte(dhcp, DHCP_OPTION_STATIC_ROUTER); - dhcp_option_byte(dhcp, DHCP_OPTION_CLASSLESS_STATIC_ROUTER); - dhcp_option_byte(dhcp, DHCP_OPTION_VSN); + dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options)); + for (u8_t i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) { + dhcp_option_byte(dhcp, dhcp_discover_request_options[i]); + } dhcp_option_trailer(dhcp); @@ -1148,6 +1138,11 @@ dhcp_renew(struct netif *netif) dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif)); + dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options)); + for (u8_t i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) { + dhcp_option_byte(dhcp, dhcp_discover_request_options[i]); + } + #if LWIP_NETIF_HOSTNAME if (netif->hostname != NULL) { const char *p = (const char*)netif->hostname; @@ -1223,6 +1218,11 @@ dhcp_rebind(struct netif *netif) dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif)); + dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options)); + for (u8_t i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) { + dhcp_option_byte(dhcp, dhcp_discover_request_options[i]); + } + #if LWIP_NETIF_HOSTNAME if (netif->hostname != NULL) { const char *p = (const char*)netif->hostname; @@ -1298,6 +1298,11 @@ dhcp_reboot(struct netif *netif) dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4); dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr))); + dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options)); + for (u8_t i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) { + dhcp_option_byte(dhcp, dhcp_discover_request_options[i]); + } + dhcp_option_trailer(dhcp); pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);