/**
 * Handle a IP address conflict after an ARP conflict detection
 */
static void
autoip_handle_arp_conflict(struct netif *netif)
{
    /* Somehow detect if we are defending or retreating */
    unsigned char defend = 1; /* tbd */

    if(defend) {
        if(netif->autoip->lastconflict > 0) {
            /* retreat, there was a conflicting ARP in the last
             * DEFEND_INTERVAL seconds
             */
            LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
                        ("autoip_handle_arp_conflict(): we are defending, but in DEFEND_INTERVAL, retreating\n"));

            /* TODO: close all TCP sessions */
            autoip_start(netif);
        } else {
            LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
                        ("autoip_handle_arp_conflict(): we are defend, send ARP Announce\n"));
            autoip_arp_announce(netif);
            netif->autoip->lastconflict = DEFEND_INTERVAL * AUTOIP_TICKS_PER_SECOND;
        }
    } else {
        LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
                    ("autoip_handle_arp_conflict(): we do not defend, retreating\n"));
        /* TODO: close all TCP sessions */
        autoip_start(netif);
    }
}
/* -----------------------------------------------------------------------------
 * 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 */
}
/**
 * Handles every incoming ARP Packet, called by etharp_arp_input.
 *
 * @param netif network interface to use for autoip processing
 * @param hdr Incoming ARP packet
 */
void
autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr)
{
    LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_arp_reply()\n"));
    if ((netif->autoip != NULL) && (netif->autoip->state != AUTOIP_STATE_OFF)) {
        /* when ip.src == llipaddr && hw.src != netif->hwaddr
         *
         * when probing  ip.dst == llipaddr && hw.src != netif->hwaddr
         * we have a conflict and must solve it
         */
        struct ip_addr 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];

        /* Copy struct ip_addr2 to aligned ip_addr, to support compilers without
         * structure packing (not using structure copy which breaks strict-aliasing rules).
         */
        SMEMCPY(&sipaddr, &hdr->sipaddr, sizeof(sipaddr));
        SMEMCPY(&dipaddr, &hdr->dipaddr, sizeof(dipaddr));

        if ((netif->autoip->state == AUTOIP_STATE_PROBING) ||
                ((netif->autoip->state == AUTOIP_STATE_ANNOUNCING) &&
                 (netif->autoip->sent_num == 0))) {
            /* RFC 3927 Section 2.2.1:
             * from beginning to after ANNOUNCE_WAIT
             * seconds we have a conflict if
             * ip.src == llipaddr OR
             * ip.dst == llipaddr && hw.src != own hwaddr
             */
            if ((ip_addr_cmp(&sipaddr, &netif->autoip->llipaddr)) ||
                    (ip_addr_cmp(&dipaddr, &netif->autoip->llipaddr) &&
                     !eth_addr_cmp(&netifaddr, &hdr->shwaddr))) {
                LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING,
                            ("autoip_arp_reply(): Probe Conflict detected\n"));
                autoip_start(netif);
            }
        } else {
            /* RFC 3927 Section 2.5:
             * in any state we have a conflict if
             * ip.src == llipaddr && hw.src != own hwaddr
             */
            if (ip_addr_cmp(&sipaddr, &netif->autoip->llipaddr) &&
                    !eth_addr_cmp(&netifaddr, &hdr->shwaddr)) {
                LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING,
                            ("autoip_arp_reply(): Conflicting ARP-Packet detected\n"));
                autoip_handle_arp_conflict(netif);
            }
        }
    }
}
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
	}
}
Exemple #5
0
/* Init lwIP TCP/IP stack */
void init_lwip_stack (unsigned int IPaddress, unsigned int NETmask, unsigned int GATEaddress, unsigned char EnDHCP, unsigned char EnAutoIP)
{
	struct ip_addr ip_addr, net_mask, gate_addr;

	/* Initialize all lwIP modules */
	lwip_init ();

	/* Setup static IP values */
	ip_addr.addr	= htonl(IPaddress);
	net_mask.addr	= htonl(NETmask);
	gate_addr.addr	= htonl(GATEaddress);

#if (LWIP_AUTOIP || LWIP_DHCP)
	/* If DHCP or AutoIP is enabled clear IP values */
	if (EnDHCP || EnAutoIP) {
		ip_addr.addr	= 0;
		net_mask.addr	= 0;
		gate_addr.addr	= 0;
	}
#endif

	/* Add a network interface to the list of lwIP netifs */
 	/* use ethernet_input() insted of tcpip_input() */
	netif_add(&enc28j60_netif, &ip_addr, &net_mask, &gate_addr, NULL, ethernetif_init, ip_input);

	/* Set a 'enc28j60_netif' interface as the default network interface */
	netif_set_default(&enc28j60_netif);

#if LWIP_DHCP
	/* Start DHCP if it enabled */
	if (EnDHCP)
		dhcp_start (&enc28j60_netif);
#endif

#if LWIP_AUTOIP
	/* Start AutoIP if it enabled */
	if (EnAutoIP)
		autoip_start (&enc28j60_netif);
#endif

	/* Bring an interface up, available for processing traffic */
	netif_set_up (&enc28j60_netif);
}
Exemple #6
0
/**
 * @brief Starts the interface in Lwip according to its mode.
 * 
 * @param lwipIf The addresses and modes to set.
 * @param ifNum The interface to set.
 * 
 * @return True if mode ok, false otherwise.
 */
static bool netifStart(LWIP_IF* const lwipIf, const unsigned int ifNum)
{
    bool ret = true;
    switch(lwipIf->ipMode)
    {
        case IPADDR_USE_DHCP:
            ret = lwIPDHCPComplete(ifNum);
            break;
        case IPADDR_USE_AUTOIP:
            autoip_start(&cpswNetIF[ifNum]);
            /*This has no break on purpose, since both autoip and static must do netif_set_up*/
        case IPADDR_USE_STATIC:
            netif_set_up(&cpswNetIF[ifNum]);
            break;
        default:
            ret = false;
    }
    return ret;
}
Exemple #7
0
/*..........................................................................*/
struct netif *eth_driver_init(QActive *active,
                              enum_t base_sig,
                              u8_t macaddr[NETIF_MAX_HWADDR_LEN])
{
    struct ip_addr ipaddr;
    struct ip_addr netmask;
    struct ip_addr gw;

    lwip_init();                                /* nitialize the lwIP stack */

                             /* set MAC address in the network interface... */
    l_netif.hwaddr_len = NETIF_MAX_HWADDR_LEN;
    memcpy(&l_netif.hwaddr[0], macaddr, NETIF_MAX_HWADDR_LEN);

    l_active = active; /*save the active object associated with this driver */

                        /* set up the static events issed by this driver... */
    l_lwipEvt[LWIP_RX_READY_OFFSET]  .sig = base_sig + LWIP_RX_READY_OFFSET;
    l_lwipEvt[LWIP_TX_READY_OFFSET]  .sig = base_sig + LWIP_TX_READY_OFFSET;
    l_lwipEvt[LWIP_RX_OVERRUN_OFFSET].sig = base_sig + LWIP_RX_OVERRUN_OFFSET;

#if LWIP_NETIF_HOSTNAME
    l_netif.hostname = "lwIP";             /* initialize interface hostname */
#endif
    l_netif.name[0] = 'Q';
    l_netif.name[1] = 'P';

    /*
    * Initialize the snmp variables and counters inside the struct netif.
    * The last argument should be replaced with your link speed, in units
    * of bits per second.
    */
    NETIF_INIT_SNMP(&l_netif, snmp_ifType_ethernet_csmacd, 1000000);

    /* We directly use etharp_output() here to save a function call.
    * You can instead declare your own function an call etharp_output()
    * from it if you have to do some checks before sending (e.g. if link
    * is available...) */
    l_netif.output     = &etharp_output;

    l_netif.linkoutput = &ethernetif_output;

#if (LWIP_DHCP == 0) && (LWIP_AUTOIP == 0)
          /* No mechanism of obtaining IP address specified, use static IP: */
    IP4_ADDR(&ipaddr,  STATIC_IPADDR0,    STATIC_IPADDR1,
                       STATIC_IPADDR2,    STATIC_IPADDR3);
    IP4_ADDR(&netmask, STATIC_NET_MASK0,  STATIC_NET_MASK1,
                       STATIC_NET_MASK2,  STATIC_NET_MASK3);
    IP4_ADDR(&gwaddr,  STATIC_GW_IPADDR0, STATIC_GW_IPADDR1,
                       STATIC_GW_IPADDR2, STATIC_GW_IPADDR3);
#else
     /* either DHCP or AUTOIP are configured, start with zero IP addresses: */
    IP4_ADDR(&ipaddr,  0, 0, 0, 0);
    IP4_ADDR(&netmask, 0, 0, 0, 0);
    IP4_ADDR(&gw,      0, 0, 0, 0);
#endif
          /* add and configure the Ethernet interface with default settings */
    netif_add(&l_netif,
              &ipaddr, &netmask, &gw,            /* configured IP addresses */
              active,                /* use this active object as the state */
              &ethernetif_init,        /* Ethernet interface initialization */
              &ip_input);                   /* standard IP input processing */

    netif_set_default(&l_netif);

    netif_set_up(&l_netif);                       /* bring the interface up */

#if (LWIP_DHCP != 0)
    dhcp_start(&l_netif);         /* start DHCP if configured in lwipopts.h */
    /* NOTE: If LWIP_AUTOIP is configured in lwipopts.h and
    * LWIP_DHCP_AUTOIP_COOP is set as well, the DHCP process will start
    * AutoIP after DHCP fails for 59 seconds.
    */
#elif (LWIP_AUTOIP != 0)
    autoip_start(&l_netif);     /* start AutoIP if configured in lwipopts.h */
#endif

    /* Enable Ethernet TX and RX Packet Interrupts. */
    ETH->IM |= (ETH_INT_RX | ETH_INT_TX);

#if LINK_STATS
    ETH->IM |= ETH_INT_RXOF;
#endif

    QS_OBJ_DICTIONARY(&l_Ethernet_IRQHandler);

    return &l_netif;
}
Exemple #8
0
/* This function initializes all network interfaces */
static void
msvc_netif_init()
{
#if USE_ETHERNET
  ip_addr_t ipaddr, netmask, gw;
#endif /* USE_ETHERNET */

#if PPP_SUPPORT
  const char *username = NULL, *password = NULL;
#ifdef PPP_USERNAME
  username = PPP_USERNAME;
#endif
#ifdef PPP_PASSWORD
  password = PPP_PASSWORD;
#endif
  printf("pppInit\n");
  pppInit();
  pppSetAuth(PPPAUTHTYPE_ANY, username, password);
  printf("pppOpen: COM%d\n", (int)sio_idx);
#if PPPOS_SUPPORT
  ppp_sio = sio_open(sio_idx);
  if (ppp_sio == NULL) {
    printf("sio_open error\n");
  } else {
    ppp_desc = pppOpen(ppp_sio, pppLinkStatusCallback, NULL);
  }
#endif /* PPPOS_SUPPORT */
#endif  /* PPP_SUPPORT */

#if USE_ETHERNET
  ip_addr_set_zero(&gw);
  ip_addr_set_zero(&ipaddr);
  ip_addr_set_zero(&netmask);
#if USE_ETHERNET_TCPIP
#if USE_DHCP
  printf("Starting lwIP, local interface IP is dhcp-enabled\n");
#elif USE_AUTOIP
  printf("Starting lwIP, local interface IP is autoip-enabled\n");
#else /* USE_DHCP */
  LWIP_PORT_INIT_GW(&gw);
  LWIP_PORT_INIT_IPADDR(&ipaddr);
  LWIP_PORT_INIT_NETMASK(&netmask);
  printf("Starting lwIP, local interface IP is %s\n", ip_ntoa(&ipaddr));
#endif /* USE_DHCP */
#endif /* USE_ETHERNET_TCPIP */

#if NO_SYS
#if LWIP_ARP
  netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, pcapif_init, ethernet_input));
#else /* LWIP_ARP */
  netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, pcapif_init, ip_input));
#endif /* LWIP_ARP */
#else  /* NO_SYS */
  netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, pcapif_init, tcpip_input));
#if LWIP_IPV6
  netif_create_ip6_linklocal_address(&netif, 1);
  printf("ip6 linklocal address: ");
  ip6_addr_debug_print(0xFFFFFFFF & ~LWIP_DBG_HALT, &netif.ip6_addr[0]);
  printf("\n");
#endif /* LWIP_IPV6 */
#endif /* NO_SYS */
#if LWIP_NETIF_STATUS_CALLBACK
  netif_set_status_callback(&netif, status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
  netif_set_link_callback(&netif, link_callback);
#endif /* LWIP_NETIF_LINK_CALLBACK */

#if USE_ETHERNET_TCPIP
#if LWIP_AUTOIP
  autoip_set_struct(&netif, &netif_autoip);
#endif /* LWIP_AUTOIP */
#if LWIP_DHCP
  dhcp_set_struct(&netif, &netif_dhcp);
#endif /* LWIP_DHCP */
#if USE_DHCP
  dhcp_start(&netif);
#elif USE_AUTOIP
  autoip_start(&netif);
#else /* USE_DHCP */
  netif_set_up(&netif);
#endif /* USE_DHCP */
#else /* USE_ETHERNET_TCPIP */
  /* Use ethernet for PPPoE only */
  netif.flags &= ~(NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP); /* no ARP */
  netif.flags |= NETIF_FLAG_ETHERNET; /* but pure ethernet */
#endif /* USE_ETHERNET_TCPIP */

#if PPP_SUPPORT && PPPOE_SUPPORT
  /* start PPPoE after ethernet netif is added! */
  ppp_desc = pppOverEthernetOpen(&netif, NULL, NULL, pppLinkStatusCallback, NULL);
#endif /* PPP_SUPPORT && PPPOE_SUPPORT */

#endif /* USE_ETHERNET */
}
//*****************************************************************************
//
// 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;
}
//*****************************************************************************
//
// Completes the initialization of lwIP.  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
lwIPPrivateInit(void *pvArg)
{
    struct ip_addr ip_addr;
    struct ip_addr net_mask;
    struct ip_addr gw_addr;

    //
    // If not using a RTOS, initialize the lwIP stack.
    //
#if NO_SYS
    lwip_init();
#endif

    //
    // If using a RTOS, create a queue (to be used as a semaphore) to signal
    // the Ethernet interrupt task from the Ethernet interrupt handler.
    //
#if !NO_SYS
    xQueueCreate(g_pcQueueMem, sizeof(g_pcQueueMem), 1, sizeof(void *),
                 &g_pInterrupt);
#endif

    //
    // If using a RTOS, create the Ethernet interrupt task.
    //
#if !NO_SYS
    xTaskCreate(lwIPInterruptTask, (signed portCHAR *)"eth_int",
                (signed portCHAR *)g_pulStack, sizeof(g_pulStack), 0, 1, 0);
#endif

    //
    // Setup the network address values.
    //
    if(g_ulIPMode == IPADDR_USE_STATIC)
    {
        ip_addr.addr = htonl(g_ulIPAddr);
        net_mask.addr = htonl(g_ulNetMask);
        gw_addr.addr = htonl(g_ulGWAddr);
    }
    else
    {
        ip_addr.addr = 0;
        net_mask.addr = 0;
        gw_addr.addr = 0;
    }

    //
    // Create, configure and add the Ethernet controller interface with
    // default settings.  ip_input should be used to send packets directly to
    // the stack when not using a RTOS and tcpip_input should be used to send
    // packets to the TCP/IP thread's queue when using a RTOS.
    //
#if NO_SYS
    netif_add(&g_sNetIF, &ip_addr, &net_mask, &gw_addr, NULL, stellarisif_init,
              ip_input);
#else
    netif_add(&g_sNetIF, &ip_addr, &net_mask, &gw_addr, NULL, stellarisif_init,
              tcpip_input);
#endif
    netif_set_default(&g_sNetIF);

    //
    // Start DHCP, if enabled.
    //
#if LWIP_DHCP
    if(g_ulIPMode == IPADDR_USE_DHCP)
    {
        dhcp_start(&g_sNetIF);
    }
#endif

    //
    // Start AutoIP, if enabled and DHCP is not.
    //
#if LWIP_AUTOIP
    if(g_ulIPMode == IPADDR_USE_AUTOIP)
    {
        autoip_start(&g_sNetIF);
    }
#endif

    //
    // Bring the interface up.
    //
    netif_set_up(&g_sNetIF);

    //
    // Setup a timeout for the host timer callback function if using a RTOS.
    //
#if !NO_SYS && HOST_TMR_INTERVAL
    sys_timeout(HOST_TMR_INTERVAL, lwIPPrivateHostTimer, NULL);
#endif

    //
    // If not running on a Fury-class device, then MDIX is handled in software.
    // In this case, when using a RTOS, setup a timeout for the soft-MDIX
    // handler.
    //
#if !NO_SYS
    if(!CLASS_IS_FURY)
    {
        sys_timeout(SOFT_MDIX_INTERVAL, lwIPSoftMDIXTimer, NULL);
    }
#endif
}
Exemple #11
0
/**
 *
 * \brief Initializes the lwIP TCP/IP stack.
 *
 * \param lwipIf  The interface structure for lwIP
 *
 * \return IP Address.
*/
unsigned int lwIPInit(LWIP_IF *lwipIf,char *hwOK)
{
    struct ip_addr ip_addr;
    struct ip_addr net_mask;
    struct ip_addr gw_addr;
    unsigned int *ipAddrPtr;
    static unsigned int lwipInitFlag = 0;
    unsigned int ifNum;
    unsigned int temp;
    
    /* do lwip library init only once */
    if(0 == lwipInitFlag)
    {
        lwip_init();
    }

    /* Setup the network address values. */
    if(lwipIf->ipMode == IPADDR_USE_STATIC)
    {
        ip_addr.addr = htonl(lwipIf->ipAddr);
        net_mask.addr = htonl(lwipIf->netMask);
        gw_addr.addr = htonl(lwipIf->gwAddr);
    }
    else
    {
        ip_addr.addr = 0;
        net_mask.addr = 0;
        gw_addr.addr = 0;
    }

#ifdef CPSW_DUAL_MAC_MODE
    ifNum = (lwipIf->instNum * MAX_SLAVEPORT_PER_INST) + lwipIf->slvPortNum - 1;
#else
    ifNum = lwipIf->instNum;
#endif

    cpswPortIf[ifNum].inst_num = lwipIf->instNum;
    cpswPortIf[ifNum].port_num = lwipIf->slvPortNum;

    /* set MAC hardware address */
    for(temp = 0; temp < LEN_MAC_ADDRESS; temp++) 
    {
        cpswPortIf[ifNum].eth_addr[temp] =
                         lwipIf->macArray[(LEN_MAC_ADDRESS - 1) - temp];
    }
    
    /*
    ** Create, configure and add the Ethernet controller interface with
    ** default settings.  ip_input should be used to send packets directly to
    ** the stack. The lwIP will internaly call the cpswif_init function. 
    */
    if(NULL ==
       netif_add(&cpswNetIF[ifNum], &ip_addr, &net_mask, &gw_addr, 
                 &cpswPortIf[ifNum], cpswif_init, ip_input,hwOK))
    {
        LWIP_PRINTF("\n\rUnable to add interface for interface %d", ifNum);
        return 0;
    }

    if(0 == lwipInitFlag)
    {
        netif_set_default(&cpswNetIF[ifNum]);
        lwipInitFlag = 1;
    }

    /* Start DHCP, if enabled. */
#if LWIP_DHCP
    if(lwipIf->ipMode == IPADDR_USE_DHCP)
    {
        lwIPDHCPComplete(ifNum);
    }
#endif

    /* Start AutoIP, if enabled and DHCP is not. */
#if LWIP_AUTOIP
    if(lwipIf->ipMode == IPADDR_USE_AUTOIP)
    {
        autoip_start(&cpswNetIF[ifNum]);
    }
#endif

    if((lwipIf->ipMode == IPADDR_USE_STATIC)
       ||(lwipIf->ipMode == IPADDR_USE_AUTOIP))
    {
       /* Bring the interface up */
       netif_set_up(&cpswNetIF[ifNum]);
    }
  
    ipAddrPtr = (unsigned int*)&(cpswNetIF[ifNum].ip_addr);

    return (*ipAddrPtr);
}
Exemple #12
0
/* This function initializes all network interfaces */
static void
msvc_netif_init()
{
#if USE_ETHERNET
  ip_addr_t ipaddr, netmask, gw;
#endif /* USE_ETHERNET */
#if USE_SLIPIF
  u8_t num_slip1 = 0;
  ip_addr_t ipaddr_slip1, netmask_slip1, gw_slip1;
#if USE_SLIPIF > 1
  u8_t num_slip2 = 1;
  ip_addr_t ipaddr_slip2, netmask_slip2, gw_slip2;
#endif /* USE_SLIPIF > 1 */
#endif /* USE_SLIPIF */

#if PPP_SUPPORT
  const char *username = NULL, *password = NULL;
#ifdef PPP_USERNAME
  username = PPP_USERNAME;
#endif
#ifdef PPP_PASSWORD
  password = PPP_PASSWORD;
#endif
  printf("pppInit\n");
  pppInit();
  pppSetAuth(PPPAUTHTYPE_ANY, username, password);
  printf("pppOpen: COM%d\n", (int)sio_idx);
#if PPPOS_SUPPORT
  ppp_sio = sio_open(sio_idx);
  if (ppp_sio == NULL) {
    printf("sio_open error\n");
  } else {
    ppp_desc = pppOpen(ppp_sio, pppLinkStatusCallback, NULL);
  }
#endif /* PPPOS_SUPPORT */
#endif  /* PPP_SUPPORT */

#if USE_ETHERNET
  ip_addr_set_zero(&gw);
  ip_addr_set_zero(&ipaddr);
  ip_addr_set_zero(&netmask);
#if USE_ETHERNET_TCPIP
#if USE_DHCP
  printf("Starting lwIP, local interface IP is dhcp-enabled\n");
#elif USE_AUTOIP
  printf("Starting lwIP, local interface IP is autoip-enabled\n");
#else /* USE_DHCP */
  LWIP_PORT_INIT_GW(&gw);
  LWIP_PORT_INIT_IPADDR(&ipaddr);
  LWIP_PORT_INIT_NETMASK(&netmask);
  printf("Starting lwIP, local interface IP is %s\n", ip_ntoa(&ipaddr));
#endif /* USE_DHCP */
#endif /* USE_ETHERNET_TCPIP */

#if NO_SYS
#if LWIP_ARP
  netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, pcapif_init, ethernet_input));
#else /* LWIP_ARP */
  netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, pcapif_init, ip_input));
#endif /* LWIP_ARP */
#else  /* NO_SYS */
  netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, pcapif_init, tcpip_input));
#endif /* NO_SYS */
#if LWIP_NETIF_STATUS_CALLBACK
  netif_set_status_callback(&netif, status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
  netif_set_link_callback(&netif, link_callback);
#endif /* LWIP_NETIF_LINK_CALLBACK */

#if USE_ETHERNET_TCPIP
#if LWIP_AUTOIP
  autoip_set_struct(&netif, &netif_autoip);
#endif /* LWIP_AUTOIP */
#if LWIP_DHCP
  dhcp_set_struct(&netif, &netif_dhcp);
#endif /* LWIP_DHCP */
#if USE_DHCP
  dhcp_start(&netif);
#elif USE_AUTOIP
  autoip_start(&netif);
#else /* USE_DHCP */
  netif_set_up(&netif);
#endif /* USE_DHCP */
#else /* USE_ETHERNET_TCPIP */
  /* Use ethernet for PPPoE only */
  netif.flags &= ~(NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP); /* no ARP */
  netif.flags |= NETIF_FLAG_ETHERNET; /* but pure ethernet */
#endif /* USE_ETHERNET_TCPIP */

#if PPP_SUPPORT && PPPOE_SUPPORT
  /* start PPPoE after ethernet netif is added! */
  ppp_desc = pppOverEthernetOpen(&netif, NULL, NULL, pppLinkStatusCallback, NULL);
#endif /* PPP_SUPPORT && PPPOE_SUPPORT */

#endif /* USE_ETHERNET */
#if USE_SLIPIF
  LWIP_PORT_INIT_SLIP1_IPADDR(&ipaddr_slip1);
  LWIP_PORT_INIT_SLIP1_GW(&gw_slip1);
  LWIP_PORT_INIT_SLIP1_NETMASK(&netmask_slip1);
  printf("Starting lwIP slipif, local interface IP is %s\n", ip_ntoa(&ipaddr_slip1));
#if SIO_USE_COMPORT
  num_slip1++; /* COM ports cannot be 0-based */
#endif
  netif_add(&slipif1, &ipaddr_slip1, &netmask_slip1, &gw_slip1, &num_slip1, slipif_init, ip_input);
#if !USE_ETHERNET
  netif_set_default(&slipif1);
#endif /* !USE_ETHERNET */
#if LWIP_NETIF_STATUS_CALLBACK
  netif_set_status_callback(&slipif1, status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
  netif_set_link_callback(&slipif1, link_callback);
#endif /* LWIP_NETIF_LINK_CALLBACK */
  netif_set_up(&slipif1);

#if USE_SLIPIF > 1
  LWIP_PORT_INIT_SLIP2_IPADDR(&ipaddr_slip2);
  LWIP_PORT_INIT_SLIP2_GW(&gw_slip2);
  LWIP_PORT_INIT_SLIP2_NETMASK(&netmask_slip2);
  printf("Starting lwIP SLIP if #2, local interface IP is %s\n", ip_ntoa(&ipaddr_slip2));
#if SIO_USE_COMPORT
  num_slip2++; /* COM ports cannot be 0-based */
#endif
  netif_add(&slipif2, &ipaddr_slip2, &netmask_slip2, &gw_slip2, &num_slip2, slipif_init, ip_input);
#if LWIP_NETIF_STATUS_CALLBACK
  netif_set_status_callback(&slipif2, status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
  netif_set_link_callback(&slipif2, link_callback);
#endif /* LWIP_NETIF_LINK_CALLBACK */
  netif_set_up(&slipif2);
#endif /* USE_SLIPIF > 1*/
#endif /* USE_SLIPIF */
}
Exemple #13
0
/* This function initializes all network interfaces */
static void
msvc_netif_init(void)
{
#if LWIP_IPV4 && USE_ETHERNET
  ip4_addr_t ipaddr, netmask, gw;
#endif /* LWIP_IPV4 && USE_ETHERNET */
#if USE_SLIPIF
  u8_t num_slip1 = 0;
#if LWIP_IPV4
  ip4_addr_t ipaddr_slip1, netmask_slip1, gw_slip1;
#endif
#if USE_SLIPIF > 1
  u8_t num_slip2 = 1;
#if LWIP_IPV4
  ip4_addr_t ipaddr_slip2, netmask_slip2, gw_slip2;
#endif
#endif /* USE_SLIPIF > 1 */
#endif /* USE_SLIPIF */
#if USE_DHCP || USE_AUTOIP
  err_t err;
#endif

#if USE_PPP
  const char *username = NULL, *password = NULL;
#ifdef PPP_USERNAME
  username = PPP_USERNAME;
#endif
#ifdef PPP_PASSWORD
  password = PPP_PASSWORD;
#endif
  printf("ppp_connect: COM%d\n", (int)sio_idx);
#if PPPOS_SUPPORT
  ppp_sio = sio_open(sio_idx);
  if (ppp_sio == NULL) {
    printf("sio_open error\n");
  } else {
    ppp = pppos_create(&ppp_netif, ppp_output_cb, pppLinkStatusCallback, NULL);
    if (ppp == NULL) {
      printf("pppos_create error\n");
    } else {
      ppp_set_auth(ppp, PPPAUTHTYPE_ANY, username, password);
      ppp_connect(ppp, 0);
    }
  }
#endif /* PPPOS_SUPPORT */
#endif  /* USE_PPP */

#if USE_ETHERNET
#if LWIP_IPV4
#define NETIF_ADDRS &ipaddr, &netmask, &gw,
  ip4_addr_set_zero(&gw);
  ip4_addr_set_zero(&ipaddr);
  ip4_addr_set_zero(&netmask);
#if USE_ETHERNET_TCPIP
#if USE_DHCP
  printf("Starting lwIP, local interface IP is dhcp-enabled\n");
#elif USE_AUTOIP
  printf("Starting lwIP, local interface IP is autoip-enabled\n");
#else /* USE_DHCP */
  LWIP_PORT_INIT_GW(&gw);
  LWIP_PORT_INIT_IPADDR(&ipaddr);
  LWIP_PORT_INIT_NETMASK(&netmask);
  printf("Starting lwIP, local interface IP is %s\n", ip4addr_ntoa(&ipaddr));
#endif /* USE_DHCP */
#endif /* USE_ETHERNET_TCPIP */
#else /* LWIP_IPV4 */
#define NETIF_ADDRS
  printf("Starting lwIP, IPv4 disable\n");
#endif /* LWIP_IPV4 */

#if NO_SYS
  netif_set_default(netif_add(&netif, NETIF_ADDRS NULL, pcapif_init, netif_input));
#else  /* NO_SYS */
  netif_set_default(netif_add(&netif, NETIF_ADDRS NULL, pcapif_init, tcpip_input));
#endif /* NO_SYS */
#if LWIP_IPV6
  netif_create_ip6_linklocal_address(&netif, 1);
  printf("ip6 linklocal address: ");
  ip6_addr_debug_print(0xFFFFFFFF & ~LWIP_DBG_HALT, netif_ip6_addr(&netif, 0));
  printf("\n");
#endif /* LWIP_IPV6 */
#if LWIP_NETIF_STATUS_CALLBACK
  netif_set_status_callback(&netif, status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
  netif_set_link_callback(&netif, link_callback);
#endif /* LWIP_NETIF_LINK_CALLBACK */

#if USE_ETHERNET_TCPIP
#if LWIP_AUTOIP
  autoip_set_struct(&netif, &netif_autoip);
#endif /* LWIP_AUTOIP */
#if LWIP_DHCP
  dhcp_set_struct(&netif, &netif_dhcp);
#endif /* LWIP_DHCP */
  netif_set_up(&netif);
#if USE_DHCP
  err = dhcp_start(&netif);
  LWIP_ASSERT("dhcp_start failed", err == ERR_OK);
#elif USE_AUTOIP
  err = autoip_start(&netif);
  LWIP_ASSERT("autoip_start failed", err == ERR_OK);
#endif /* USE_DHCP */
#else /* USE_ETHERNET_TCPIP */
  /* Use ethernet for PPPoE only */
  netif.flags &= ~(NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP); /* no ARP */
  netif.flags |= NETIF_FLAG_ETHERNET; /* but pure ethernet */
#endif /* USE_ETHERNET_TCPIP */

#if USE_PPP && PPPOE_SUPPORT
  /* start PPPoE after ethernet netif is added! */
  ppp = pppoe_create(&ppp_netif, &netif, NULL, NULL, pppLinkStatusCallback, NULL);
  if (ppp == NULL) {
    printf("pppos_create error\n");
  } else {
    ppp_set_auth(ppp, PPPAUTHTYPE_ANY, username, password);
    ppp_connect(ppp, 0);
  }
#endif /* USE_PPP && PPPOE_SUPPORT */

#endif /* USE_ETHERNET */
#if USE_SLIPIF
#if LWIP_IPV4
#define SLIP1_ADDRS &ipaddr_slip1, &netmask_slip1, &gw_slip1,
  LWIP_PORT_INIT_SLIP1_IPADDR(&ipaddr_slip1);
  LWIP_PORT_INIT_SLIP1_GW(&gw_slip1);
  LWIP_PORT_INIT_SLIP1_NETMASK(&netmask_slip1);
  printf("Starting lwIP slipif, local interface IP is %s\n", ip4addr_ntoa(&ipaddr_slip1));
#else
#define SLIP1_ADDRS
  printf("Starting lwIP slipif\n");
#endif
#if defined(SIO_USE_COMPORT) && SIO_USE_COMPORT
  num_slip1++; /* COM ports cannot be 0-based */
#endif
  netif_add(&slipif1, SLIP1_ADDRS &num_slip1, slipif_init, ip_input);
#if !USE_ETHERNET
  netif_set_default(&slipif1);
#endif /* !USE_ETHERNET */
#if LWIP_IPV6
  netif_create_ip6_linklocal_address(&slipif1, 1);
  printf("SLIP ip6 linklocal address: ");
  ip6_addr_debug_print(0xFFFFFFFF & ~LWIP_DBG_HALT, netif_ip6_addr(&slipif1, 0));
  printf("\n");
#endif /* LWIP_IPV6 */
#if LWIP_NETIF_STATUS_CALLBACK
  netif_set_status_callback(&slipif1, status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
  netif_set_link_callback(&slipif1, link_callback);
#endif /* LWIP_NETIF_LINK_CALLBACK */
  netif_set_up(&slipif1);

#if USE_SLIPIF > 1
#if LWIP_IPV4
#define SLIP2_ADDRS &ipaddr_slip2, &netmask_slip2, &gw_slip2,
  LWIP_PORT_INIT_SLIP2_IPADDR(&ipaddr_slip2);
  LWIP_PORT_INIT_SLIP2_GW(&gw_slip2);
  LWIP_PORT_INIT_SLIP2_NETMASK(&netmask_slip2);
  printf("Starting lwIP SLIP if #2, local interface IP is %s\n", ip4addr_ntoa(&ipaddr_slip2));
#else
#define SLIP2_ADDRS
  printf("Starting lwIP SLIP if #2\n");
#endif
#if defined(SIO_USE_COMPORT) && SIO_USE_COMPORT
  num_slip2++; /* COM ports cannot be 0-based */
#endif
  netif_add(&slipif2, SLIP2_ADDRS &num_slip2, slipif_init, ip_input);
#if LWIP_IPV6
  netif_create_ip6_linklocal_address(&slipif1, 1);
  printf("SLIP2 ip6 linklocal address: ");
  ip6_addr_debug_print(0xFFFFFFFF & ~LWIP_DBG_HALT, netif_ip6_addr(&slipif2, 0));
  printf("\n");
#endif /* LWIP_IPV6 */
#if LWIP_NETIF_STATUS_CALLBACK
  netif_set_status_callback(&slipif2, status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
  netif_set_link_callback(&slipif2, link_callback);
#endif /* LWIP_NETIF_LINK_CALLBACK */
  netif_set_up(&slipif2);
#endif /* USE_SLIPIF > 1*/
#endif /* USE_SLIPIF */
}
Exemple #14
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
	}
}
Exemple #15
0
/**************************************************************************//**
 * @brief Initializes the lwIP TCP/IP stack.
 * \param pucMAC is a pointer to a six byte array containing the MAC
 * address to be used for the interface.
 * \param ulIPAddr is the IP address to be used (static).
 * \param ulNetMask is the network mask to be used (static).
 * \param ulGWAddr is the Gateway address to be used (static).
 * \param ulIPMode is the IP Address Mode.  \b IPADDR_USE_STATIC 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 performs initialization of the lwIP TCP/IP stack for the
 * AX88796 Ethernet MAC, including DHCP and/or AutoIP, as configured.
 * \return None.
 *****************************************************************************/
void
lwIPInit(const unsigned char *pucMAC, unsigned long ulIPAddr,
         unsigned long ulNetMask, unsigned long ulGWAddr,
         unsigned long ulIPMode)
{
  (void) pucMAC;

  struct ip_addr ip_addr;
  struct ip_addr net_mask;
  struct ip_addr gw_addr;


/* Check the parameters.*/
#if LWIP_DHCP && LWIP_AUTOIP
  EFM_ASSERT((ulIPMode == IPADDR_USE_STATIC) ||
             (ulIPMode == IPADDR_USE_DHCP) ||
             (ulIPMode == IPADDR_USE_AUTOIP));
#elif LWIP_DHCP
  EFM_ASSERT((ulIPMode == IPADDR_USE_STATIC) ||
             (ulIPMode == IPADDR_USE_DHCP));
#elif LWIP_AUTOIP
  EFM_ASSERT((ulIPMode == IPADDR_USE_STATIC) ||
             (ulIPMode == IPADDR_USE_AUTOIP));
#else
  EFM_ASSERT(ulIPMode == IPADDR_USE_STATIC);
#endif

  /* Initialize lwIP library modules */
  lwip_init();

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

  /* Create, configure and add the Ethernet controller interface with
   * default settings.*/
  netif_add(&lwip_netif, &ip_addr, &net_mask, &gw_addr, NULL,
            AX88796Cif_init, ip_input);

  netif_set_default(&lwip_netif);


  /* Start DHCP, if enabled.*/
#if LWIP_DHCP
  if (ulIPMode == IPADDR_USE_DHCP)
  {
    dhcp_start(&lwip_netif);
  }
#endif

  /* Start AutoIP, if enabled and DHCP is not.*/
#if LWIP_AUTOIP
  if (ulIPMode == IPADDR_USE_AUTOIP)
  {
    autoip_start(&lwip_netif);
  }
#endif

  /* Bring the interface up.*/
  netif_set_up(&lwip_netif);
}
Exemple #16
0
/** Restart AutoIP client and check the next address (conflict detected)
 *
 * @param netif The netif under AutoIP control
 */
static void
ICACHE_FLASH_ATTR autoip_restart(struct netif *netif)
{
  netif->autoip->tried_llipaddr++;
  autoip_start(netif);
}
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
    }
}
Exemple #18
0
void lwIPInit(const unsigned char *pucMAC, 
         struct ip_addr* ipAddr,
         struct ip_addr* netMask, 
				 struct ip_addr* gwAddr,
         u8_t ulIPMode)
{

    //
    // Initialize lwIP library modules
    //
    lwip_init();

    //
    // Setup the network address values.
    //
#if LWIP_DHCP || LWIP_AUTOIP
    if(ulIPMode != IPADDR_USE_STATIC)
    {
        ipAddr->addr = 0;
        netMask->addr = 0;
        gwAddr->addr = 0;
    }
#endif

    //
    // Create, configure and add the Ethernet controller interface with
    // default settings.
    //
		lwip_netif.hwaddr[0]=pucMAC[0];
		lwip_netif.hwaddr[1]=pucMAC[1];
		lwip_netif.hwaddr[2]=pucMAC[2];
		lwip_netif.hwaddr[3]=pucMAC[3];
		lwip_netif.hwaddr[4]=pucMAC[4];
		lwip_netif.hwaddr[5]=pucMAC[5];

    netif_add(&lwip_netif, ipAddr, netMask, gwAddr, 0,
              enc28j60_if_init, ip_input);

    netif_set_default(&lwip_netif);

    g_ulIPMode = ulIPMode;

    //
    // Start DHCP, if enabled.
    //
#if LWIP_DHCP
    if(g_ulIPMode == IPADDR_USE_DHCP)
    {
        dhcp_start(&lwip_netif);
    }
#endif

    //
    // Start AutoIP, if enabled and DHCP is not.
    //
#if LWIP_AUTOIP
    if(g_ulIPMode == IPADDR_USE_AUTOIP)
    {
        autoip_start(&lwip_netif);
    }
#endif

    //
    // Bring the interface up.
    //
    netif_set_up(&lwip_netif);
}
Exemple #19
0
//*****************************************************************************
//
//! Initializes the lwIP TCP/IP stack.
//!
//! \param pucMAC is a pointer to a six byte array containing the MAC
//! address to be used for the interface.
//! \param ulIPAddr is the IP address to be used (static).
//! \param ulNetMask is the network mask to be used (static).
//! \param ulGWAddr is the Gateway address to be used (static).
//! \param ulIPMode is the IP Address Mode.  \b IPADDR_USE_STATIC 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 performs initialization of the lwIP TCP/IP stack for the
//! Stellaris Ethernet MAC, including DHCP and/or AutoIP, as configured.
//!
//! \return None.
//
//*****************************************************************************
void LWIPServiceTaskInit(void *pvParameters)
{
	struct ip_addr *ip_addr;
	struct ip_addr *net_mask;
	struct ip_addr *gw_addr;

	//struct ip_addr ip_addr_local;
	//struct ip_addr net_mask_local;

	char IPState = 0;

	char* configLoad;

	IP_CONFIG * ipCfg;

	printf("Initialisiere IP ");
	ipCfg = pvPortMalloc(sizeof(IP_CONFIG));

	configLoad = loadFromConfig(IP_CONFIG_FILE, "USE_DHCP");

#ifdef ENABLE_GRAPHIC
	vShowBootText("load ipconfig ...");
#endif

	printf("LWIPSTACK: LOAD CONFIG: (%s)\n", configLoad);
	if (configLoad == 0)
	{
		IPState = IPADDR_USE_AUTOIP;
	}
	else if (strcmp(configLoad, "true") == 0)
	{
		IPState = IPADDR_USE_DHCP;
	}
	else
	{
		IPState = IPADDR_USE_STATIC;
	}

	vPortFree(configLoad);

	// Start the TCP/IP thread & init stuff
	tcpip_init(NULL, NULL);

	vTaskDelay(100 / portTICK_RATE_MS);

	// Setup the network address values.
	if (IPState == IPADDR_USE_STATIC)
	{
		ip_addr = getAddresFromConfig("IP_ADDRESS");
		net_mask = getAddresFromConfig("IP_SUBNETMASK");
		gw_addr = getAddresFromConfig("IP_GATEWAY");
	}
#if LWIP_DHCP || LWIP_AUTOIP
	else
	{
		ip_addr = pvPortMalloc(sizeof(struct ip_addr));
		net_mask = pvPortMalloc(sizeof(struct ip_addr));
		gw_addr = pvPortMalloc(sizeof(struct ip_addr));
	}
#endif

	// Create, configure and add the Ethernet controller interface with
	// default settings.
	// WARNING: This must only be run after the OS has been started.
	// Typically this is the case, however, if not, you must place this
	// in a post-OS initialization
	// @SEE http://lwip.wikia.com/wiki/Initialization_using_tcpip.c

	printf("Starting NETIF ... \n");
#ifdef ENABLE_GRAPHIC
	vShowBootText("starting Network ...");
#endif
	netif_add(&lwip_netif, ip_addr, net_mask, gw_addr, NULL, ethernetif_init,
			tcpip_input);
	netif_set_default(&lwip_netif);

	printf("NETIF UP\n");

	// Start DHCP, if enabled.
#if LWIP_DHCP
	if (IPState == IPADDR_USE_DHCP)
	{
#ifdef ENABLE_GRAPHIC
		vShowBootText("waiting for DHCP ...");
#endif
		printf("Starte DHCP Client ...     ");
		if (dhcp_start(&lwip_netif) == ERR_OK)
		{
			printf("[ok]\n");
		}
		else
		{
			printf("[fail]\n");
		}
	}
#endif

	// Start AutoIP, if enabled and DHCP is not.
#if LWIP_AUTOIP
	if (IPState == IPADDR_USE_AUTOIP)
	{
		printf ("Setzte Auto IP (NICHT DHCP) ...\n");
		autoip_start(&lwip_netif);
	}
#endif

	if (IPState == IPADDR_USE_STATIC)
	{
		// Bring the interface up.
		netif_set_up(&lwip_netif);
	}
	vTaskDelay(1000 / portTICK_RATE_MS);

	while (0 == netif_is_up(&lwip_netif))
	{
		vTaskDelay(5000 / portTICK_RATE_MS);
		if (0 == netif_is_up(&lwip_netif))
		{
			dhcp_renew(&lwip_netif);
		}
	}

	printnetif(&lwip_netif);

	configLoad = loadFromConfig(IP_CONFIG_FILE, "IS_SERVER");
	if (strcmp(configLoad, "true") == 0)
	{
		/* Initialize HTTP, DNS, SNTP */
		printf("HTTPD Starten ...\n");
		httpd_init();
	}
	vPortFree(configLoad);

#if ENABLE_SNTP
	printf("SNTP Starten ...\n");
	sntp_init();
#endif

#if ENABLE_DNS
	printf("DNS Starten ...\n");
	dns_init();
#endif

#if ENABLE_NET_BIOS
	printf("NETBIOS Starten ...\n");
	netbios_init();
#endif

	printf("Dienste gestartet ...\n");

#ifdef ENABLE_GRAPHIC
	configLoad = loadFromConfig(IP_CONFIG_FILE, "IS_CLIENT");
	if (strcmp(configLoad, "true") == 0)
	{
		vShowBootText("loading menu ...");
		vLoadMenu();
	}
	else
	{
		vShowBootText("ready for requests ...");
	}
	vPortFree(configLoad);
#endif

	// Nothing else to do.  No point hanging around.
	while (1)
	{
		vTaskDelay(500 / portTICK_RATE_MS);
		if (EthernetPHYRead(ETH_BASE, PHY_MR1) & ETH_PHY_LINK_UP)
		{
			if (!(netif_is_up(&lwip_netif)))
			{
				// set link up flag
				netif_set_up(&lwip_netif);
#ifdef ENABLE_GRAPHIC
				vShowBootText("activate networkinterface ...");
				configLoad = loadFromConfig(IP_CONFIG_FILE, "IS_CLIENT");
				if (strcmp(configLoad, "true") == 0)
				{
					vShowBootText("loading menu ...");
					vLoadMenu();
				}
				else
				{
					vShowBootText("ready for requests ...");
				}
				vPortFree(configLoad);
#endif
				if (IPState == IPADDR_USE_DHCP)
				{
					printf("DHCP Adresse anfordern ...  ");
					if (dhcp_renew(&lwip_netif) == ERR_OK)
					{
						printf("[ok]\n");
						printnetif(&lwip_netif);
					}
					else
					{
						printf("[fail]\n");
					}
				}
			}
		}
		else
		{
			if (netif_is_up(&lwip_netif))
			{
#ifdef ENABLE_GRAPHIC
				vShowBootText("no networkconnection!!");
#endif
				printf("Deaktiviere Netzwerkinterface ...  ");
				netif_set_down(&lwip_netif);
			}
		}

	}
}
Exemple #20
0
//*****************************************************************************
//
//! Initializes the lwIP TCP/IP stack.
//! Call it from your main to initialize the lwip
//!
//! \param pucMAC is a pointer to a six byte array containing the MAC
//! address to be used for the interface.
//! \param ulIPAddr is the IP address to be used (static).
//! \param ulNetMask is the network mask to be used (static).
//! \param ulGWAddr is the Gateway address to be used (static).
//! \param ulIPMode is the IP Address Mode.  \b IPADDR_USE_STATIC 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 performs initialization of the lwIP TCP/IP stack for the
//! Stellaris Ethernet MAC, including DHCP and/or AutoIP, as configured.
//!
//! \return None.
//
//*****************************************************************************
void LWIPServiceTaskInit(IP_CONFIG *ipCfg)
{
	struct ip_addr ip_addr;
	struct ip_addr net_mask;
	struct ip_addr gw_addr;

	LWIP_ASSERT("ipCfg != NULL", (ipCfg != NULL));

	// 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

	LWIP_DEBUGF(DHCP_DEBUG, ("----- LWIP_DEBUGF calling tcpip_init -----\n"));
	// Start the TCP/IP thread & init stuff
	tcpip_init(NULL, NULL);

	vTaskDelay(100 / portTICK_RATE_MS);

	// 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);
	}
	else
	{
		ip_addr.addr = 0;
		net_mask.addr = 0;
		gw_addr.addr = 0;
	}

	// Create, configure and add the Ethernet controller interface with
	// default settings.
	// WARNING: This must only be run after the OS has been started.
	// Typically this is the case, however, if not, you must place this
	// in a post-OS initialization
	// @SEE http://lwip.wikia.com/wiki/Initialization_using_tcpip.c
	netif_add(&lwip_netif, &ip_addr, &net_mask, &gw_addr,
			NULL, ethernetif_init, tcpip_input);
	netif_set_default(&lwip_netif);

	// Start DHCP, if enabled.
#if LWIP_DHCP
	if (ipCfg->IPMode == IPADDR_USE_DHCP)
	{
		LWIP_DEBUGF(DHCP_DEBUG, ("----- Starting DHCP client -----\n"));
		dhcp_start(&lwip_netif);
	}
#endif

	// Start AutoIP, if enabled and DHCP is not.
#if LWIP_AUTOIP
	if (ipCfg->IPMode == IPADDR_USE_AUTOIP)
	{
		autoip_start(&lwip_netif);
	}
#endif

	if (ipCfg->IPMode == IPADDR_USE_STATIC)
	{
		// Bring the interface up.
		netif_set_up(&lwip_netif);
	}

	vTaskDelay(1000/portTICK_RATE_MS);

	while (0 == netif_is_up(&lwip_netif))
	{
		lstr("<delay 5s>");
		vTaskDelay(5000/portTICK_RATE_MS);
#if LWIP_DHCP
		if (ipCfg->IPMode == IPADDR_USE_DHCP) {
			if (0 == netif_is_up(&lwip_netif)) {
				lstr("<dhcp_renew>");
				dhcp_renew(&lwip_netif);
			}
		}
#endif
	}

	/* Initialize HTTP */

#ifdef INCLUDE_HTTPD_SSI
	init_ssi_cgi_handlers();
#else
#ifdef INCLUDE_HTTPD_CGI
	init_ssi_cgi_handlers();
#endif
#endif
	httpd_init();
}
Exemple #21
0
/** Restart AutoIP client and check the next address (conflict detected)
 *
 * @param netif The netif under AutoIP control
 */
static void
autoip_restart(struct netif *netif)
{
  netif->autoip->tried_llipaddr++;
  autoip_start(netif);
}
/*..........................................................................*/
QState LwIPMgr_running(LwIPMgr *me, QEvt const *e) {
    switch (e->sig) {
        case Q_ENTRY_SIG: {
#if (LWIP_DHCP != 0)
            dhcp_start(me->netif);              /* start DHCP if configured */
            /* NOTE: If LWIP_AUTOIP is configured in lwipopts.h and
            * LWIP_DHCP_AUTOIP_COOP is set as well, the DHCP process will
            * start AutoIP after DHCP fails for 59 seconds.
            */
#elif (LWIP_AUTOIP != 0)
            autoip_start(me->netif);          /* start AutoIP if configured */
#endif
            QTimeEvt_postEvery(&me->te_LWIP_SLOW_TICK, (QActive *)me,
                (LWIP_SLOW_TICK_MS * BSP_TICKS_PER_SEC) / 1000U);
            return Q_HANDLED();
        }
        case Q_EXIT_SIG: {
            QTimeEvt_disarm(&me->te_LWIP_SLOW_TICK);
            return Q_HANDLED();
        }

        case SEND_UDP_SIG: {
            if (me->upcb->remote_port != 0U) {
                struct pbuf *p = pbuf_new((u8_t *)((TextEvt const *)e)->text,
                                     strlen(((TextEvt const *)e)->text) + 1U);
                if (p != (struct pbuf *)0) {
                    udp_send(me->upcb, p);
                    pbuf_free(p);                   /* don't leak the pbuf! */
                }
            }
            return Q_HANDLED();
        }

        case LWIP_RX_READY_SIG: {
            eth_driver_read();
            return Q_HANDLED();
        }
        case LWIP_TX_READY_SIG: {
            eth_driver_write();
            return Q_HANDLED();
        }
        case LWIP_SLOW_TICK_SIG: {
                                                 /* has IP address changed? */
            if (me->ip_addr != me->netif->ip_addr.addr) {
                me->ip_addr = me->netif->ip_addr.addr; /* save the IP addr. */
                BSP_displyIP(ntohl(me->ip_addr));
            }

#if LWIP_TCP
            me->tcp_tmr += LWIP_SLOW_TICK_MS;
            if (me->tcp_tmr >= TCP_TMR_INTERVAL) {
                me->tcp_tmr = 0;
                tcp_tmr();
            }
#endif
#if LWIP_ARP
            me->arp_tmr += LWIP_SLOW_TICK_MS;
            if (me->arp_tmr >= ARP_TMR_INTERVAL) {
                me->arp_tmr = 0;
                etharp_tmr();
            }
#endif
#if LWIP_DHCP
            me->dhcp_fine_tmr += LWIP_SLOW_TICK_MS;
            if (me->dhcp_fine_tmr >= DHCP_FINE_TIMER_MSECS) {
                me->dhcp_fine_tmr = 0;
                dhcp_fine_tmr();
            }
            me->dhcp_coarse_tmr += LWIP_SLOW_TICK_MS;
            if (me->dhcp_coarse_tmr >= DHCP_COARSE_TIMER_MSECS) {
                me->dhcp_coarse_tmr = 0;
                dhcp_coarse_tmr();
            }
#endif
#if LWIP_AUTOIP
            me->auto_ip_tmr += LWIP_SLOW_TICK_MS;
            if (me->auto_ip_tmr >= AUTOIP_TMR_INTERVAL) {
                me->auto_ip_tmr = 0;
                autoip_tmr();
            }
#endif
            return Q_HANDLED();
        }
        case LWIP_RX_OVERRUN_SIG: {
            LINK_STATS_INC(link.err);
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&QHsm_top);
}