From 3cf377b06e372f7a7842a460dd260cb885b10447 Mon Sep 17 00:00:00 2001 From: Wu Jian Gang Date: Fri, 2 Sep 2016 20:00:45 +0800 Subject: [PATCH] dhcp: add dhcp callback The callback has no parameter now. TODO: add a parameter to show dhcp status if needed. --- components/lwip/core/ipv4/dhcp.c | 41 +++++++++++++----------- components/lwip/include/lwip/lwip/dhcp.h | 8 +++++ 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/components/lwip/core/ipv4/dhcp.c b/components/lwip/core/ipv4/dhcp.c index 079880e671..cd780d00ae 100755 --- a/components/lwip/core/ipv4/dhcp.c +++ b/components/lwip/core/ipv4/dhcp.c @@ -710,6 +710,24 @@ void dhcp_cleanup(struct netif *netif) } } +/* Espressif add start. */ + +/** Set callback for dhcp, reversed parameter for future use. + * + * @param netif the netif from which to remove the struct dhcp + * @param cb callback for chcp + */ +void dhcp_set_cb(struct netif *netif, void (*cb)(void)) +{ + LWIP_ASSERT("netif != NULL", netif != NULL); + + if (netif->dhcp != NULL) { + netif->dhcp->cb = cb; + } +} + +/* Espressif add end. */ + /** * Start DHCP negotiation for a network interface. * @@ -1117,32 +1135,19 @@ dhcp_bind(struct netif *netif) } #endif /* LWIP_DHCP_AUTOIP_COOP */ - /* Espressif add start. */ - /* back up old ip/netmask/gw */ - ip4_addr_t ip, mask, gw; - ip4_addr_set(&ip, ip_2_ip4(&netif->ip_addr)); - ip4_addr_set(&mask, ip_2_ip4(&netif->netmask)); - ip4_addr_set(&gw, ip_2_ip4(&netif->gw)); - /* Espressif add end. */ - LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): IP: 0x%08"X32_F" SN: 0x%08"X32_F" GW: 0x%08"X32_F"\n", ip4_addr_get_u32(&dhcp->offered_ip_addr), ip4_addr_get_u32(&sn_mask), ip4_addr_get_u32(&gw_addr))); netif_set_addr(netif, &dhcp->offered_ip_addr, &sn_mask, &gw_addr); /* interface is used by routing now that an address is set */ -#ifdef LWIP_ESP8266 - /* use old ip/mask/gw to check whether ip/mask/gw changed */ -// extern void system_station_got_ip_set(ip4_addr_t *ip, ip4_addr_t *mask, ip4_addr_t *gw); -// system_station_got_ip_set(&ip, &mask, &gw); -#endif - - /* use old ip/mask/gw to check whether ip/mask/gw changed */ -// extern void system_station_got_ip_set(ip4_addr_t *ip, ip4_addr_t *mask, ip4_addr_t *gw); -// system_station_got_ip_set(&ip, &mask, &gw); - /* netif is now bound to DHCP leased address */ dhcp_set_state(dhcp, DHCP_STATE_BOUND); + /* Espressif add start. */ + if (dhcp->cb != NULL) { + dhcp->cb(); + } + /* Espressif add end. */ } /** diff --git a/components/lwip/include/lwip/lwip/dhcp.h b/components/lwip/include/lwip/lwip/dhcp.h index 57b6359573..2d8926eca6 100755 --- a/components/lwip/include/lwip/lwip/dhcp.h +++ b/components/lwip/include/lwip/lwip/dhcp.h @@ -94,6 +94,10 @@ struct dhcp ip_addr_t offered_si_addr; char boot_file_name[DHCP_FILE_LEN]; #endif /* LWIP_DHCP_BOOTPFILE */ + + /* Espressif add start. */ + void (*cb)(void); /* callback for dhcp, add a parameter to show dhcp status if needed */ + /* Espressif add end. */ }; /* MUST be compiled with "pack structs" or equivalent! */ @@ -140,6 +144,10 @@ void dhcp_set_struct(struct netif *netif, struct dhcp *dhcp); /** Remove a struct dhcp previously set to the netif using dhcp_set_struct() */ #define dhcp_remove_struct(netif) do { (netif)->dhcp = NULL; } while(0) void dhcp_cleanup(struct netif *netif); +/* Espressif add start. */ +/** set callback for DHCP */ +void dhcp_set_cb(struct netif *netif, void (*cb)(void)); +/* Espressif add end. */ /** start DHCP configuration */ err_t dhcp_start(struct netif *netif); /** enforce early lease renewal (not needed normally)*/