/* -----------------------------------------------------------------------------
 * When a cable is plugged in, this function is called
 * ---------------------------------------------------------------------------*/
void uip_linkup() {
	if (uip_xtcp_get_ifstate()){
		uip_xtcp_down();
	}
#if UIP_CONF_IPV4
	if (uip_static_ip) {
		uip_sethostaddr(&uip_static_ipconfig.ipaddr);
		uip_setdraddr(&uip_static_ipconfig.gateway);
		uip_setnetmask(&uip_static_ipconfig.netmask);
		uip_xtcp_up();
	} else {
		dhcp_done = 0;
#if UIP_USE_DHCP
		dhcpc_stop();
#endif
#if UIP_USE_AUTOIP
#if UIP_USE_DHCP
		autoip_stop();
#else
		autoip_start();
#endif
#endif
#if UIP_USE_DHCP
		dhcpc_start();
#endif
	}
#endif /* UIP_CONF_IPVx */
}
/* -----------------------------------------------------------------------------
 * When a cable is unplugged in, this function is called
 * ---------------------------------------------------------------------------*/
void uip_linkdown() {
	dhcp_done = 0;
#if UIP_USE_DHCP
	dhcpc_stop();
#endif
#if UIP_USE_AUTOIP
	autoip_stop();
#endif
	uip_xtcp_down();
}
void dhcpc_configured(const struct dhcpc_state *s) {
#ifdef XTCP_VERBOSE_DEBUG
	printf("dhcp: ");uip_printip4(s->ipaddr);printf("\n");
#endif
#if UIP_USE_AUTOIP
	autoip_stop();
#endif
	uip_sethostaddr(s->ipaddr);
	uip_setdraddr(s->default_router);
	uip_setnetmask(s->netmask);
	uip_xtcp_up();
	dhcp_done = 1;
}
void uip_linkup() {
	if (get_uip_xtcp_ifstate())
		uip_xtcp_down();

	if (uip_static_ip) {
#if UIP_CONF_IPV6
		uip_ipaddr_t ipaddr;
		uip_ipaddr(ipaddr,
				uip_static_ipconfig.ipaddr[0],
				uip_static_ipconfig.ipaddr[1],
				uip_static_ipconfig.ipaddr[2],
				uip_static_ipconfig.ipaddr[3]);
		uip_sethostaddr(ipaddr);
		uip_ipaddr(ipaddr,
				uip_static_ipconfig.gateway[0],
				uip_static_ipconfig.gateway[1],
				uip_static_ipconfig.gateway[2],
				uip_static_ipconfig.gateway[3]);
		uip_setdraddr(ipaddr);
		uip_ipaddr(ipaddr,
				uip_static_ipconfig.netmask[0],
				uip_static_ipconfig.netmask[1],
				uip_static_ipconfig.netmask[2],
				uip_static_ipconfig.netmask[3]);
		uip_setnetmask(ipaddr);
		uip_setsubnetaddr();
#else
		uip_sethostaddr(uip_static_ipconfig.ipaddr);
		uip_setdraddr(uip_static_ipconfig.gateway);
		uip_setnetmask(uip_static_ipconfig.netmask);
		uip_setsubnetaddr();
#endif
		uip_xtcp_up();
	} else {
		dhcp_done = 0;
#if UIP_USE_DHCP
		dhcpc_stop();
#endif
#if UIP_USE_AUTOIP
#if UIP_USE_DHCP
		autoip_stop();
#else
		autoip_start();
#endif
#endif
#if UIP_USE_DHCP
		dhcpc_start();
#endif
	}
}
Beispiel #5
0
//*****************************************************************************
//
//! Change the configuration of the lwIP network interface.
//!
//! \param ulIPAddr is the new IP address to be used (static).
//! \param ulNetMask is the new network mask to be used (static).
//! \param ulGWAddr is the new Gateway address to be used (static).
//! \param ulIPMode is the IP Address Mode.  \b IPADDR_USE_STATIC 0 will force
//! static IP addressing to be used, \b IPADDR_USE_DHCP will force DHCP with
//! fallback to Link Local (Auto IP), while \b IPADDR_USE_AUTOIP will force
//! Link Local only.
//!
//! This function will evaluate the new configuration data.  If necessary, the
//! interface will be brought down, reconfigured, and then brought back up
//! with the new configuration.
//!
//! \return None.
//
//*****************************************************************************
void lwIPNetworkConfigChange(struct netif *netif, IP_CONFIG * ipCfg)
{
	struct ip_addr ip_addr;
	struct ip_addr net_mask;
	struct ip_addr gw_addr;

	IP_CONFIG currentIPConfig;

	// Check the parameters.
#if LWIP_DHCP && LWIP_AUTOIP
	ASSERT((ipCfg->IPMode == IPADDR_USE_STATIC) ||
			(ipCfg->IPMode == IPADDR_USE_DHCP) ||
			(ipCfg->IPMode == IPADDR_USE_AUTOIP))
#elif LWIP_DHCP
	ASSERT((ipCfg->IPMode == IPADDR_USE_STATIC) ||
			(ipCfg->IPMode == IPADDR_USE_DHCP))
#elif LWIP_AUTOIP
	ASSERT((ipCfg->IPMode == IPADDR_USE_STATIC) ||
			(ipCfg->IPMode == IPADDR_USE_AUTOIP))
#else
	ASSERT(ipCfg->IPMode == IPADDR_USE_STATIC)
#endif

	// Setup the network address values.

	if (ipCfg->IPMode == IPADDR_USE_STATIC)
	{
		ip_addr.addr = htonl(ipCfg->IPAddr);
		net_mask.addr = htonl(ipCfg->NetMask);
		gw_addr.addr = htonl(ipCfg->GWAddr);
	}
#if LWIP_DHCP || LWIP_AUTOIP
	else
	{
		ip_addr.addr = 0;
		net_mask.addr = 0;
		gw_addr.addr = 0;
	}
#endif

	// Switch on the current IP Address Aquisition mode.
	currentIPConfig.IPMode = IPADDR_USE_DHCP;
	LWIPServiceTaskIPConfigGet(netif, &currentIPConfig);

	switch (currentIPConfig.IPMode)
	{
	// Static IP

	case IPADDR_USE_STATIC:
	{
		// Set the new address parameters.  This will change the address
		// configuration in lwIP, and if necessary, will reset any links
		// that are active.  This is valid for all three modes.
		//
		netif_set_addr(netif, &ip_addr, &net_mask, &gw_addr);

		// If we are going to DHCP mode, then start the DHCP server now.
#if LWIP_DHCP
		if (ipCfg->IPMode == IPADDR_USE_DHCP)
		{
			dhcp_start(netif);
		}
#endif
		// If we are going to AutoIP mode, then start the AutoIP process
		// now.
#if LWIP_AUTOIP
		if (ipCfg->IPMode == IPADDR_USE_AUTOIP)
		{
			autoip_start(netif);
		}
#endif
		// And we're done.
		break;
	}

		// DHCP (with AutoIP fallback).
#if LWIP_DHCP
	case IPADDR_USE_DHCP:
	{
		//
		// If we are going to static IP addressing, then disable DHCP and
		// force the new static IP address.
		//
		if (ipCfg->IPMode == IPADDR_USE_STATIC)
		{
			dhcp_stop(netif);
			// SEE bug http://savannah.nongnu.org/bugs/?22804
			netif->flags &= ~NETIF_FLAG_DHCP;
			netif_set_addr(netif, &ip_addr, &net_mask, &gw_addr);
		}
		// If we are going to AUTO IP addressing, then disable DHCP, set
		// the default addresses, and start AutoIP.
#if LWIP_AUTOIP
		else if (ipCfg->IPMode == IPADDR_USE_AUTOIP)
		{
			dhcp_stop(netif);
			netif_set_addr(netif, &ip_addr, &net_mask, &gw_addr);
			autoip_start(netif);
		}
#endif
		break;
	}
#endif
		// AUTOIP
#if LWIP_AUTOIP
		case IPADDR_USE_AUTOIP:
		{
			//
			// If we are going to static IP addressing, then disable AutoIP and
			// force the new static IP address.
			//
			if (ulIPMode == IPADDR_USE_STATIC)
			{
				autoip_stop(netif);
				netif_set_addr(netif, &ip_addr, &net_mask, &gw_addr);
			}

			//
			// If we are going to DHCP addressing, then disable AutoIP, set the
			// default addresses, and start dhcp.
			//
#if LWIP_DHCP
			else if (ulIPMode == IPADDR_USE_AUTOIP)
			{
				autoip_stop(netif);
				netif_set_addr(netif, &ip_addr, &net_mask, &gw_addr);
				dhcp_start(netif);
			}
#endif
			break;
		}
#endif
	}
}
//*****************************************************************************
//
// Completes the network configuration change.  This is directly called when
// not using a RTOS and provided as a callback to the TCP/IP thread when using
// a RTOS.
//
//*****************************************************************************
static void
lwIPPrivateNetworkConfigChange(void *pvArg)
{
    unsigned long ulIPMode;
    struct ip_addr ip_addr;
    struct ip_addr net_mask;
    struct ip_addr gw_addr;

    //
    // Get the new address mode.
    //
    ulIPMode = (unsigned long)pvArg;

    //
    // Setup the network address values.
    //
    if(ulIPMode == IPADDR_USE_STATIC)
    {
        ip_addr.addr = htonl(g_ulIPAddr);
        net_mask.addr = htonl(g_ulNetMask);
        gw_addr.addr = htonl(g_ulGWAddr);
    }
#if LWIP_DHCP || LWIP_AUTOIP
    else
    {
        ip_addr.addr = 0;
        net_mask.addr = 0;
        gw_addr.addr = 0;
    }
#endif

    //
    // Switch on the current IP Address Aquisition mode.
    //
    switch(g_ulIPMode)
    {
        //
        // Static IP
        //
        case IPADDR_USE_STATIC:
        {
            //
            // Set the new address parameters.  This will change the address
            // configuration in lwIP, and if necessary, will reset any links
            // that are active.  This is valid for all three modes.
            //
            netif_set_addr(&g_sNetIF, &ip_addr, &net_mask, &gw_addr);

            //
            // If we are going to DHCP mode, then start the DHCP server now.
            //
#if LWIP_DHCP
            if(ulIPMode == IPADDR_USE_DHCP)
            {
                dhcp_start(&g_sNetIF);
            }
#endif

            //
            // If we are going to AutoIP mode, then start the AutoIP process
            // now.
            //
#if LWIP_AUTOIP
            if(ulIPMode == IPADDR_USE_AUTOIP)
            {
                autoip_start(&g_sNetIF);
            }
#endif
            //
            // And we're done.
            //
            break;
        }

        //
        // DHCP (with AutoIP fallback).
        //
#if LWIP_DHCP
        case IPADDR_USE_DHCP:
        {
            //
            // If we are going to static IP addressing, then disable DHCP and
            // force the new static IP address.
            //
            if(ulIPMode == IPADDR_USE_STATIC)
            {
                dhcp_stop(&g_sNetIF);
                netif_set_addr(&g_sNetIF, &ip_addr, &net_mask, &gw_addr);
            }

            //
            // If we are going to AUTO IP addressing, then disable DHCP, set
            // the default addresses, and start AutoIP.
            //
#if LWIP_AUTOIP
            else if(ulIPMode == IPADDR_USE_AUTOIP)
            {
                dhcp_stop(&g_sNetIF);
                netif_set_addr(&g_sNetIF, &ip_addr, &net_mask, &gw_addr);
                autoip_start(&g_sNetIF);
            }
#endif
            break;
        }
#endif

        //
        // AUTOIP
        //
#if LWIP_AUTOIP
        case IPADDR_USE_AUTOIP:
        {
            //
            // If we are going to static IP addressing, then disable AutoIP and
            // force the new static IP address.
            //
            if(ulIPMode == IPADDR_USE_STATIC)
            {
                autoip_stop(&g_sNetIF);
                netif_set_addr(&g_sNetIF, &ip_addr, &net_mask, &gw_addr);
            }

            //
            // If we are going to DHCP addressing, then disable AutoIP, set the
            // default addresses, and start dhcp.
            //
#if LWIP_DHCP
            else if(ulIPMode == IPADDR_USE_DHCP)
            {
                autoip_stop(&g_sNetIF);
                netif_set_addr(&g_sNetIF, &ip_addr, &net_mask, &gw_addr);
                dhcp_start(&g_sNetIF);
            }
#endif
            break;
        }
#endif
    }

    //
    // Save the new mode.
    //
    g_ulIPMode = ulIPMode;
}
Beispiel #7
0
//*****************************************************************************
//
//! Service the lwIP timers.
//!
//! This function services all of the lwIP periodic timers, including TCP and
//! Host timers.  This should be called from the lwIP context, which may be
//! the Ethernet interrupt (in the case of a non-RTOS system) or the lwIP
//! thread, in the event that an RTOS is used.
//!
//! \return None.
//
//*****************************************************************************
static void lwIPServiceTimers(struct netif *netif)
{
	LWIP_DRIVER_DATA* drv_data = (LWIP_DRIVER_DATA*)netif;
	MAC_Type* mac = (MAC_Type*)netif->state;
    //
    // Service the MDIX timer.
    //
    if(drv_data->timer_main > drv_data->timer_mdix)
    {
        //
        // See if there has not been a link for 2 seconds.
        //
        if((EthernetPHYRead(mac, PHY_MR1) & PHY_MR1_LINK) == 0)
        {
            // There has not been a link for 2 seconds, so flip the MDI/MDIX
            // switch.  This is handled automatically by Fury rev A2, but is
            // harmless.
            //
        	mac->MDIX  ^= MAC_MDIX_EN;
       	    if (netif->flags & NETIF_FLAG_LINK_UP)
			{
#if LWIP_DHCP
                autoip_stop(netif);
                dhcp_start(netif);
#endif
				netif_set_link_down(netif);
			}
		}
		else
			netif_set_link_up(netif);
        //
        // Reset the MDIX timer.
        //
    	drv_data->timer_mdix = drv_data->timer_main + 2048;
    }

    //
    // Service the host timer.
    //
#if HOST_TMR_INTERVAL
    if(drv_data->timer_main > drv_data->timer_host )
    {
    	drv_data->timer_host = drv_data->timer_main + HOST_TMR_INTERVAL;
        lwIPHostTimerHandler();
    }
#endif

    //
    // Service the ARP timer.
    //
#if LWIP_ARP
    if(drv_data->timer_main > drv_data->timer_arp)
    {
    	drv_data->timer_arp = drv_data->timer_main + ARP_TMR_INTERVAL;
        etharp_tmr();
    }
#endif

    //
    // Service the TCP timer.
    //
#if LWIP_TCP
    if(drv_data->timer_main > drv_data->timer_tcp)
    {
    	drv_data->timer_tcp = drv_data->timer_main + TCP_TMR_INTERVAL;
        tcp_tmr();
    }
#endif

    //
    // Service the AutoIP timer.
    //
#if LWIP_AUTOIP
    if(drv_data->timer_main - drv_data->timer_autoIP)
    {
    	drv_data->timer_autoIP = drv_data->timer_main + AUTOIP_TMR_INTERVAL;
        autoip_tmr();
    }
#endif

    //
    // Service the DCHP Coarse Timer.
    //
#if LWIP_DHCP
    if(drv_data->timer_main > drv_data->timer_DHCPCoarse)
    {
    	drv_data->timer_DHCPCoarse = drv_data->timer_main + DHCP_COARSE_TIMER_MSECS;
        dhcp_coarse_tmr();
    }
#endif

    //
    // Service the DCHP Fine Timer.
    //
#if LWIP_DHCP
    if(drv_data->timer_main > drv_data->timer_DHCPFine)
    {
    	drv_data->timer_DHCPFine = drv_data->timer_main + DHCP_FINE_TIMER_MSECS;
        dhcp_fine_tmr();
    }
#endif
}
static void
lwIPLinkDetect(void)
{
    bool bHaveLink;
    struct ip_addr ip_addr;
    struct ip_addr net_mask;
    struct ip_addr gw_addr;

    //
    // See if there is an active link.
    //
    bHaveLink = MAP_EMACPHYRead(EMAC0_BASE, 0, EPHY_BMSR) & EPHY_BMSR_LINKSTAT;

    //
    // Return without doing anything else if the link state hasn't changed.
    //
    if(bHaveLink == g_bLinkActive)
    {
        return;
    }

    //
    // Save the new link state.
    //
    g_bLinkActive = bHaveLink;

    //
    // Clear any address information from the network interface.
    //
    ip_addr.addr = 0;
    net_mask.addr = 0;
    gw_addr.addr = 0;
    netif_set_addr(&g_sNetIF, &ip_addr, &net_mask, &gw_addr);

    //
    // See if there is a link now.
    //
    if(bHaveLink)
    {
        //
        // Start DHCP, if enabled.
        //
#if LWIP_DHCP
        if(g_ui32IPMode == IPADDR_USE_DHCP)
        {
            dhcp_start(&g_sNetIF);
        }
#endif

        //
        // Start AutoIP, if enabled and DHCP is not.
        //
#if LWIP_AUTOIP
        if(g_ui32IPMode == IPADDR_USE_AUTOIP)
        {
            autoip_start(&g_sNetIF);
        }
#endif
    }
    else
    {
        //
        // Stop DHCP, if enabled.
        //
#if LWIP_DHCP
        if(g_ui32IPMode == IPADDR_USE_DHCP)
        {
            dhcp_stop(&g_sNetIF);
        }
#endif

        //
        // Stop AutoIP, if enabled and DHCP is not.
        //
#if LWIP_AUTOIP
        if(g_ui32IPMode == IPADDR_USE_AUTOIP)
        {
            autoip_stop(&g_sNetIF);
        }
#endif
    }
}