dhcp: add dhcp callback

The callback has no parameter now.
TODO: add a parameter to show dhcp status if needed.
pull/21/head
Wu Jian Gang 2016-09-02 20:00:45 +08:00
rodzic ef23607a67
commit 3cf377b06e
2 zmienionych plików z 31 dodań i 18 usunięć

Wyświetl plik

@ -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. */
}
/**

Wyświetl plik

@ -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)*/