Index: dhcp.c =================================================================== RCS file: /sources/lwip/lwip/src/core/dhcp.c,v retrieving revision 1.130 diff -u -r1.130 dhcp.c --- dhcp.c 15 Jun 2010 20:21:30 -0000 1.130 +++ dhcp.c 16 Jun 2010 19:52:44 -0000 @@ -615,7 +615,7 @@ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); /* Remove the flag that says this netif is handled by DHCP, it is set when we succeeded starting. */ - netif->flags &= ~NETIF_FLAG_DHCP; + netif->flags &= ~(NETIF_FLAG_DHCP|NETIF_FLAG_AUTOIP); /* check hwtype of the netif */ if ((netif->flags & NETIF_FLAG_ETHARP) == 0) { @@ -982,6 +982,7 @@ netif_set_up(netif); /* netif is now bound to DHCP leased address */ dhcp_set_state(dhcp, DHCP_BOUND); + netif->flags = (netif->flags | NETIF_FLAG_DHCP) & ~NETIF_FLAG_AUTOIP; } /** @@ -1212,18 +1213,21 @@ struct dhcp *dhcp; LWIP_ERROR("dhcp_stop: netif != NULL", (netif != NULL), return;); dhcp = netif->dhcp; - /* Remove the flag that says this netif is handled by DHCP. */ + /* Remove the flag that says this netif is handled by DHCP. + Possibly leaves NETIF_FLAG_AUTOIP set so an app can choose + to disable DHCP when detecting the address is AutoIP. */ netif->flags &= ~NETIF_FLAG_DHCP; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_stop()\n")); /* netif is DHCP configured? */ if (dhcp != NULL) { -#if LWIP_DHCP_AUTOIP_COOP - if(dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) { - autoip_stop(netif); - dhcp->autoip_coop_state = DHCP_AUTOIP_COOP_STATE_OFF; - } -#endif /* LWIP_DHCP_AUTOIP_COOP */ +// Delete this if we agree that we do not want to do this on a dhcp_stop! +//#if LWIP_DHCP_AUTOIP_COOP +// if(dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) { +// autoip_stop(netif); +// dhcp->autoip_coop_state = DHCP_AUTOIP_COOP_STATE_OFF; +// } +//#endif /* LWIP_DHCP_AUTOIP_COOP */ if (dhcp->pcb != NULL) { udp_remove(dhcp->pcb); Index: netif.c =================================================================== RCS file: /sources/lwip/lwip/src/core/netif.c,v retrieving revision 1.90 diff -u -r1.90 netif.c --- netif.c 15 Mar 2010 09:47:43 -0000 1.90 +++ netif.c 16 Jun 2010 20:19:22 -0000 @@ -151,8 +151,10 @@ netif->dhcp = NULL; #endif /* LWIP_DHCP */ #if LWIP_AUTOIP - /* netif not under AutoIP control by default */ + /* netif not under AutoIP control by default + No user-defined IP address. */ netif->autoip = NULL; + ip_addr_set_zero(&netif->autoip_fallback_addr); #endif /* LWIP_AUTOIP */ #if LWIP_NETIF_STATUS_CALLBACK netif->status_callback = NULL; Index: autoip.c =================================================================== RCS file: /sources/lwip/lwip/src/core/ipv4/autoip.c,v retrieving revision 1.32 diff -u -r1.32 autoip.c --- autoip.c 14 Jun 2010 20:27:14 -0000 1.32 +++ autoip.c 16 Jun 2010 20:22:22 -0000 @@ -150,6 +150,19 @@ netif->autoip = autoip; } +/** Set AutoIP fallback IP address. Used instead of random one + * to allow the user to fall back to a static IP address. + * + * @param netif the netif for which to set the struct autoip + * @param ipaddr the IP address to fall back to. + */ +void autoip_set_ip_addr(struct netif *netif, ip_addr_t *ipaddr) +{ + LWIP_ASSERT("netif != NULL", netif != NULL); + LWIP_ASSERT("netif->autoip != NULL", netif->autoip != NULL); + ip_addr_set_hton(&netif->autoip_fallback_addr, ipaddr); +} + /** Restart AutoIP client and check the next address (conflict detected) * * @param netif The netif under AutoIP control @@ -157,7 +170,8 @@ static void autoip_restart(struct netif *netif) { - netif->autoip->tried_llipaddr++; + if(!ip_addr_isany(&netif->autoip_fallback_addr)) + netif->autoip->tried_llipaddr++; autoip_start(netif); } @@ -280,6 +294,7 @@ /* bring the interface up */ netif_set_up(netif); + netif->flags = (netif->flags | NETIF_FLAG_AUTOIP) & ~NETIF_FLAG_DHCP; return ERR_OK; } @@ -331,7 +346,11 @@ autoip->lastconflict = 0; } - autoip_create_addr(netif, &(autoip->llipaddr)); + netif->flags &= ~NETIF_FLAG_AUTOIP; + if(!ip_addr_isany(&netif->autoip_fallback_addr)) + ip_addr_set_hton(&autoip->llipaddr, &netif->autoip_fallback_addr); + else + autoip_create_addr(netif, &(autoip->llipaddr)); autoip_start_probing(netif); return result; @@ -494,12 +513,7 @@ */ ip_addr_t sipaddr, dipaddr; struct eth_addr netifaddr; - netifaddr.addr[0] = netif->hwaddr[0]; - netifaddr.addr[1] = netif->hwaddr[1]; - netifaddr.addr[2] = netif->hwaddr[2]; - netifaddr.addr[3] = netif->hwaddr[3]; - netifaddr.addr[4] = netif->hwaddr[4]; - netifaddr.addr[5] = netif->hwaddr[5]; + ETHADDR16_COPY(netifaddr.addr, netif->hwaddr); /* Copy struct ip_addr2 to aligned ip_addr, to support compilers without * structure packing (not using structure copy which breaks strict-aliasing rules). Index: autoip.h =================================================================== RCS file: /sources/lwip/lwip/src/include/ipv4/lwip/autoip.h,v retrieving revision 1.9 diff -u -r1.9 autoip.h --- autoip.h 22 May 2010 21:01:38 -0000 1.9 +++ autoip.h 16 Jun 2010 20:24:24 -0000 @@ -95,6 +95,10 @@ /** Set a struct autoip allocated by the application to work with */ void autoip_set_struct(struct netif *netif, struct autoip *autoip); +/** Set AutoIP fallback IP address. Used instead of random one + to allow the user to fall back to a static IP address. */ +void autoip_set_ip_addr(struct netif *netif, ip_addr_t *ipaddr); + /** Start AutoIP client */ err_t autoip_start(struct netif *netif); Index: netif.h =================================================================== RCS file: /sources/lwip/lwip/src/include/lwip/netif.h,v retrieving revision 1.58 diff -u -r1.58 netif.h --- netif.h 15 Feb 2010 19:53:46 -0000 1.58 +++ netif.h 16 Jun 2010 20:19:22 -0000 @@ -93,6 +93,9 @@ /** If set, the netif has IGMP capability. * Set by the netif driver in its init function. */ #define NETIF_FLAG_IGMP 0x80U +/** If set, the netif has an AutoIP IP address. + * Set by AutoIP when an IP address is bound to the netif. */ +#define NETIF_FLAG_AUTOIP 0x100U /** Function prototype for netif init functions. Set up flags and output/linkoutput * callback functions in this function. @@ -173,6 +176,7 @@ #if LWIP_AUTOIP /** the AutoIP client state information for this netif */ struct autoip *autoip; + ip_addr_t autoip_fallback_addr; #endif #if LWIP_NETIF_HOSTNAME /* the hostname for this netif, NULL is a valid value */ @@ -185,7 +189,7 @@ /** link level hardware address of this interface */ u8_t hwaddr[NETIF_MAX_HWADDR_LEN]; /** flags (see NETIF_FLAG_ above) */ - u8_t flags; + u16_t flags; /** descriptive abbreviation */ char name[2]; /** number of this interface */