Exemple #1
0
/* Internal API to preserve existing PPP functionality - revise to better match mbed_ipstak_add_ethernet_interface later */
nsapi_error_t LWIP::_add_ppp_interface(void *hw, bool default_if, nsapi_ip_stack_t stack, LWIP::Interface **interface_out)
{
#if LWIP_PPP_API
    Interface *interface = new (std::nothrow) Interface();
    if (!interface) {
        return NSAPI_ERROR_NO_MEMORY;
    }
    interface->hw = hw;
    interface->ppp = true;

    nsapi_error_t ret = ppp_lwip_if_init(hw, &interface->netif, stack);
    if (ret != NSAPI_ERROR_OK) {
        free(interface);
        return ret;
    }

    if (default_if) {
        netif_set_default(&interface->netif);
        default_interface = interface;
    }

    netif_set_link_callback(&interface->netif, &LWIP::Interface::netif_link_irq);
    netif_set_status_callback(&interface->netif, &LWIP::Interface::netif_status_irq);

    *interface_out = interface;

    return NSAPI_ERROR_OK;
#else
    return NSAPI_ERROR_UNSUPPORTED;
#endif //LWIP_PPP_API
}
Exemple #2
0
nsapi_error_t mbed_lwip_init(emac_interface_t *emac)
{
    // Check if we've already brought up lwip
    if (!mbed_lwip_get_mac_address()) {
        // Set up network
        mbed_lwip_set_mac_address();

        sys_sem_new(&lwip_tcpip_inited, 0);
        sys_sem_new(&lwip_netif_linked, 0);
        sys_sem_new(&lwip_netif_has_addr, 0);

        tcpip_init(mbed_lwip_tcpip_init_irq, NULL);
        sys_arch_sem_wait(&lwip_tcpip_inited, 0);

        memset(&lwip_netif, 0, sizeof lwip_netif);
        if (!netif_add(&lwip_netif,
#if LWIP_IPV4
                       0, 0, 0,
#endif
                       emac, MBED_NETIF_INIT_FN, tcpip_input)) {
            return NSAPI_ERROR_DEVICE_ERROR;
        }

        netif_set_default(&lwip_netif);

        netif_set_link_callback(&lwip_netif, mbed_lwip_netif_link_irq);
        netif_set_status_callback(&lwip_netif, mbed_lwip_netif_status_irq);

#if !DEVICE_EMAC
        eth_arch_enable_interrupts();
#endif
    }

    return NSAPI_ERROR_OK;
}
/**
  * @brief  Start lwip service in a certain operation mode.
  * @param[in] uint8_t opmode: the target operation mode.
  * @retval None
  */
void lwip_net_start(uint8_t opmode)
{
    struct netif *sta_if;
    struct netif *ap_if;

    switch(opmode) {
        case WIFI_MODE_STA_ONLY:
        case WIFI_MODE_REPEATER:
            wifi_connection_register_event_handler(WIFI_EVENT_IOT_PORT_SECURE, wifi_station_port_secure_event_handler);
            wifi_connection_register_event_handler(WIFI_EVENT_IOT_DISCONNECTED, wifi_station_disconnected_event_handler);
        #if USE_DHCP
            sta_if = netif_find_by_type(NETIF_TYPE_STA);
            netif_set_default(sta_if);
            netif_set_status_callback(sta_if, ip_ready_callback);
            dhcp_start(sta_if);
        #endif
            break;
        case WIFI_MODE_AP_ONLY: {
            dhcpd_settings_t dhcpd_settings = {{0},{0},{0},{0},{0},{0},{0}};
            strcpy((char *)dhcpd_settings.dhcpd_server_address, AP_IPADDR);
            strcpy((char *)dhcpd_settings.dhcpd_netmask, AP_NETMASK);
            strcpy((char *)dhcpd_settings.dhcpd_gateway, AP_GATEWAY);
            strcpy((char *)dhcpd_settings.dhcpd_primary_dns, PRIMARY_DNS);
            strcpy((char *)dhcpd_settings.dhcpd_secondary_dns, SECONDARY_DNS);
            strcpy((char *)dhcpd_settings.dhcpd_ip_pool_start, IP_POOL_START);
            strcpy((char *)dhcpd_settings.dhcpd_ip_pool_end, IP_POOL_END);
            ap_if = netif_find_by_type(NETIF_TYPE_AP);
            netif_set_default(ap_if);
            netif_set_link_up(ap_if);
            dhcpd_start(&dhcpd_settings);
            break;
        }
    }
}
Exemple #4
0
//
// Called from the network driver to indicate a new netif.
//
void
lwip_eth_drv_new(struct netif *netif)
{
#ifdef CYGFUN_LWIP_SHOW_NETIF_CONFIG
    netif_set_status_callback(netif, netif_status_callback);
#endif
}
Exemple #5
0
/***************************************************************************
* Function: Tcpip_stack_init
*
* Description: This function is init ip stack.
*
* Input:
*		ipaddr:
*		netmask:
*       gateway:
* Output:
*
* Return:
*		netif: Init IP Stack OK
*       NULL : Init IP Statck Fail Because no memory
* Date : 2014-6-4
****************************************************************************/
struct netif *Tcpip_stack_init()
{
#if TLS_CONFIG_APSTA
    struct netif *nif4apsta = NULL;
#endif

    /*Register Ethernet Rx Data callback From wifi*/
    tls_ethernet_data_rx_callback(ethernetif_input);
#if TLS_CONFIG_APSTA
    tls_ethernet_ip_rx_callback(alg_input);
#endif

    /* Setup lwIP. */
    tcpip_init(NULL, NULL);

#if TLS_CONFIG_APSTA
    /* add net info for apsta's ap */
    nif4apsta = (struct netif *)tls_mem_alloc(sizeof(struct netif));
    if (nif4apsta == NULL)
        return NULL;
#endif

    /*Add Net Info to Netif, default */
    nif = (struct netif *)tls_mem_alloc(sizeof(struct netif));
    if (nif == NULL)
    {
#if TLS_CONFIG_APSTA
        tls_mem_free(nif4apsta);
#endif
        return NULL;
    }

#if TLS_CONFIG_APSTA
    memset(nif4apsta, 0, sizeof(struct netif));
    nif->next = nif4apsta;
    netifapi_netif_add(nif4apsta, IPADDR_ANY, IPADDR_ANY, IPADDR_ANY, NULL, ethernetif_init, tcpip_input);
    netif_set_status_callback(nif4apsta, netif_status_changed);
#endif

    memset(nif, 0, sizeof(struct netif));
    netifapi_netif_add(nif, IPADDR_ANY,IPADDR_ANY,IPADDR_ANY,NULL,ethernetif_init,tcpip_input);
    netifapi_netif_set_default(nif);
    dl_list_init(&netif_status_event.list);
    netif_set_status_callback(nif, netif_status_changed);
    tls_wifi_status_change_cb_register(wifi_status_changed);
    return nif;
}
Exemple #6
0
void 
main(void)
{
  struct netif netif;

  lwip_init();

  netif_add(&netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY, NULL, netif_init, netif_input);
  netif.name[0] = 'e';
  netif.name[1] = '0';
  netif_create_ip6_linklocal_address(&netif, 1);
  netif.ip6_autoconfig_enabled = 1;
  netif_set_status_callback(&netif, netif_status_callback);
  netif_set_default(&netif);
  netif_set_up(&netif);
  
  /* Start DHCP and HTTPD */
  dhcp_start(&netif );
  httpd_init();

  while(1) {
    /* Check link state, e.g. via MDIO communication with PHY */
    if(link_state_changed()) {
      if(link_is_up()) {
        netif_set_link_up(&netif);
      } else {
        netif_set_link_down(&netif);
      }
    }

    /* Check for received frames, feed them to lwIP */
    lock_interrupts();
    struct pbuf* p = queue_try_get(&queue);
    unlock_interrupts();

    if(p != NULL) {
      LINK_STATS_INC(link.recv);
 
      /* Update SNMP stats (only if you use SNMP) */
      MIB2_STATS_NETIF_ADD(netif, ifinoctets, p->tot_len);
      int unicast = ((p->payload[0] & 0x01) == 0);
      if (unicast) {
        MIB2_STATS_NETIF_INC(netif, ifinucastpkts);
      } else {
        MIB2_STATS_NETIF_INC(netif, ifinnucastpkts);
      }

      if(netif.input(p, &netif) != ERR_OK) {
        pbuf_free(p);
      }
    }
     
    /* Cyclic lwIP timers check */
    sys_check_timeouts();
     
    /* your application goes here */
  }
}
static void init_netif(ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw) {
    tcpip_init(tcpip_init_done, NULL);
    tcpip_inited.wait();
    
    memset((void*) &lpcNetif, 0, sizeof(lpcNetif));
    netif_add(&lpcNetif, ipaddr, netmask, gw, NULL, lpc_enetif_init, tcpip_input);
    netif_set_default(&lpcNetif);
    netif_set_status_callback(&lpcNetif, netif_status_callback);
}
Exemple #8
0
/* Called from the TCP/IP thread. */
void lwIPAppsInit( void *pvArgument )
{
ip_addr_t xIPAddr, xNetMask, xGateway;
extern err_t xemacpsif_init( struct netif *netif );
extern void xemacif_input_thread( void *netif );
static struct netif xNetIf;

	( void ) pvArgument;

	/* Set up the network interface. */
	ip_addr_set_zero( &xGateway );
	ip_addr_set_zero( &xIPAddr );
	ip_addr_set_zero( &xNetMask );

	LWIP_PORT_INIT_GW(&xGateway);
	LWIP_PORT_INIT_IPADDR( &xIPAddr );
	LWIP_PORT_INIT_NETMASK(&xNetMask);

	/* Set mac address */
	xNetIf.hwaddr_len = 6;
	xNetIf.hwaddr[ 0 ] = configMAC_ADDR0;
	xNetIf.hwaddr[ 1 ] = configMAC_ADDR1;
	xNetIf.hwaddr[ 2 ] = configMAC_ADDR2;
	xNetIf.hwaddr[ 3 ] = configMAC_ADDR3;
	xNetIf.hwaddr[ 4 ] = configMAC_ADDR4;
	xNetIf.hwaddr[ 5 ] = configMAC_ADDR5;

	netif_set_default( netif_add( &xNetIf, &xIPAddr, &xNetMask, &xGateway, ( void * ) XPAR_XEMACPS_0_BASEADDR, xemacpsif_init, tcpip_input ) );
	netif_set_status_callback( &xNetIf, vStatusCallback );
	#if LWIP_DHCP
	{
		dhcp_start( &xNetIf );
	}
	#else
	{
		netif_set_up( &xNetIf );
	}
	#endif

	/* Install the server side include handler. */
	http_set_ssi_handler( uslwIPAppsSSIHandler, pccSSITags, sizeof( pccSSITags ) / sizeof( char * ) );

	/* Create the mutex used to ensure mutual exclusive access to the Tx 
	buffer. */
	xTxBufferMutex = xSemaphoreCreateMutex();
	configASSERT( xTxBufferMutex );

	/* Create the httpd server from the standard lwIP code.  This demonstrates
	use of the lwIP raw API. */
	httpd_init();

	sys_thread_new( "lwIP_In", xemacif_input_thread, &xNetIf, configMINIMAL_STACK_SIZE, configMAC_INPUT_TASK_PRIORITY );

	/* Create the FreeRTOS defined basic command server.  This demonstrates use
	of the lwIP sockets API. */
	xTaskCreate( vBasicSocketsCommandInterpreterTask, "CmdInt", configMINIMAL_STACK_SIZE * 5, NULL, configCLI_TASK_PRIORITY, NULL );
}
Exemple #9
0
nsapi_error_t LWIP::add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out)
{
#if LWIP_ETHERNET
    Interface *interface = new (std::nothrow) Interface();
    if (!interface) {
        return NSAPI_ERROR_NO_MEMORY;
    }
    interface->emac = &emac;
    interface->memory_manager = &memory_manager;
    interface->ppp = false;

#if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
    netif->interface.hwaddr[0] = MBED_MAC_ADDR_0;
    netif->interface.hwaddr[1] = MBED_MAC_ADDR_1;
    netif->interface.hwaddr[2] = MBED_MAC_ADDR_2;
    netif->interface.hwaddr[3] = MBED_MAC_ADDR_3;
    netif->interface.hwaddr[4] = MBED_MAC_ADDR_4;
    netif->interface.hwaddr[5] = MBED_MAC_ADDR_5;
#else
    mbed_mac_address((char *) interface->netif.hwaddr);
#endif

    interface->netif.hwaddr_len = 6;

    if (!netif_add(&interface->netif,
#if LWIP_IPV4
                   0, 0, 0,
#endif
                   interface, &LWIP::Interface::emac_if_init, tcpip_input)) {
        return NSAPI_ERROR_DEVICE_ERROR;
    }

    if (default_if) {
        netif_set_default(&interface->netif);
        default_interface = interface;
    }

    netif_set_link_callback(&interface->netif, &LWIP::Interface::netif_link_irq);
    netif_set_status_callback(&interface->netif, &LWIP::Interface::netif_status_irq);

    *interface_out = interface;

    /* Use mac address as additional seed to random number generator */
    uint64_t seed = interface->netif.hwaddr[0];
    for (uint8_t i = 1; i < 8; i++) {
        seed <<= 8;
        seed |= interface->netif.hwaddr[i % 6];
    }
    lwip_add_random_seed(seed);

    return NSAPI_ERROR_OK;
#else
    return NSAPI_ERROR_UNSUPPORTED;
#endif //LWIP_ETHERNET
}
Exemple #10
0
/**
 * \brief Configure ethernet interface.
 */
static void ethernet_configure_interface(void)
{
	struct ip_addr x_ip_addr, x_net_mask, x_gateway;
	extern err_t ethernetif_init(struct netif *netif);

	if (g_ip_mode == 2) {
		/* DHCP mode. */
		x_ip_addr.addr = 0;
		x_net_mask.addr = 0;
	}
	else {
		/* Fixed IP mode. */
		/* Default IP addr */
		IP4_ADDR(&x_ip_addr, ETHERNET_CONF_IPADDR0, ETHERNET_CONF_IPADDR1,
				ETHERNET_CONF_IPADDR2, ETHERNET_CONF_IPADDR3);

		/* Default subnet mask. */
		IP4_ADDR(&x_net_mask, ETHERNET_CONF_NET_MASK0, ETHERNET_CONF_NET_MASK1,
				ETHERNET_CONF_NET_MASK2, ETHERNET_CONF_NET_MASK3);

		/* Default gateway addr. */
		IP4_ADDR(&x_gateway, ETHERNET_CONF_GATEWAY_ADDR0,
				ETHERNET_CONF_GATEWAY_ADDR1,
				ETHERNET_CONF_GATEWAY_ADDR2,
				ETHERNET_CONF_GATEWAY_ADDR3);
	}

	/* Add data to netif. */
	/* Use ethernet_input as input method for standalone lwIP mode. */
	/* Use tcpip_input as input method for threaded lwIP mode. */
	if (NULL == netif_add(&gs_net_if, &x_ip_addr, &x_net_mask, &x_gateway, NULL,
			ethernetif_init, tcpip_input)) {
		LWIP_ASSERT("NULL == netif_add", 0);
	}

	/* Make it the default interface. */
	netif_set_default(&gs_net_if);

	/* Setup callback function for netif status change. */
	netif_set_status_callback(&gs_net_if, status_callback);

	/* Bring it up. */
	if (g_ip_mode == 2) {
		/* DHCP mode. */
		if (ERR_OK != dhcp_start(&gs_net_if)) {
			LWIP_ASSERT("ERR_OK != dhcp_start", 0);
		}
	}
	else {
		/* Static mode. */
		netif_set_up(&gs_net_if);
	}

}
static void init_netif(ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw) {
	init_mySemaphore(&tcpip_inited, 0);
	init_mySemaphore(&netif_inited, 0);

	tcpip_init(tcpip_init_done, NULL);
	wait_mySemaphore(&tcpip_inited, osWaitForever);
    
	memset((void*) &lpcNetif, 0, sizeof(lpcNetif));
	netif_add(&lpcNetif, ipaddr, netmask, gw, NULL, lpc_enetif_init, tcpip_input);
	netif_set_default(&lpcNetif);
	netif_set_status_callback(&lpcNetif, netif_status_callback);
}
Exemple #12
0
/**
 * \brief Configure network interface driver.
 */
static void ethernet_configure_interface(void)
{
	struct ip_addr x_ip_addr, x_net_mask, x_gateway;
	extern err_t ethernetif_init(struct netif *netif);

#if defined(DHCP_USED)
		/* DHCP mode. */
	x_ip_addr.addr = 0;
	x_net_mask.addr = 0;
#else
	/* Fixed IP mode. */
	/* Default ip addr */
	IP4_ADDR(&x_ip_addr, ETHERNET_CONF_IPADDR0, ETHERNET_CONF_IPADDR1,
			ETHERNET_CONF_IPADDR2, ETHERNET_CONF_IPADDR3);

	/* Default subnet mask */
	IP4_ADDR(&x_net_mask, ETHERNET_CONF_NET_MASK0, ETHERNET_CONF_NET_MASK1,
			ETHERNET_CONF_NET_MASK2, ETHERNET_CONF_NET_MASK3);

	/* Default gateway addr */
	IP4_ADDR(&x_gateway, ETHERNET_CONF_GATEWAY_ADDR0,
			ETHERNET_CONF_GATEWAY_ADDR1,
			ETHERNET_CONF_GATEWAY_ADDR2,
			ETHERNET_CONF_GATEWAY_ADDR3);
#endif

	/* Add data to netif */
	if (NULL == netif_add(&gs_net_if, &x_ip_addr, &x_net_mask, &x_gateway, NULL,
			ethernetif_init, ethernet_input)) {
		LWIP_ASSERT("NULL == netif_add", 0);
	}

	/* Make it the default interface */
	netif_set_default(&gs_net_if);

	/* Setup callback function for netif status change */
	netif_set_status_callback(&gs_net_if, status_callback);

	/* Bring it up */
#if defined(DHCP_USED)
	/* DHCP mode. */
	if (ERR_OK != dhcp_start(&gs_net_if)) {
		LWIP_ASSERT("ERR_OK != dhcp_start", 0);
	}
	printf("DHCP Started\r\n");
#else
	/* Static mode. */
	netif_set_up(&gs_net_if);
	printf("Static IP Address Assigned\r\n");
#endif
}
Exemple #13
0
/**
 * Callback for tcpip_init()
 */
static void tcpip_init_cb(void *args){/*{{{*/
    ip_addr_t ip_addr;
    ip_addr_t netmask;
    ip_addr_t gw_addr;
    BaseType_t retval;
    eth_int_q_handle = xQueueCreate(1, sizeof(uint32_t));

    retval = xTaskCreate( eth_int_task,
            "eth_int",
            ETH_INT_STACK,
            NULL,
            tskIDLE_PRIORITY+ETH_PRIO,
            &eth_int_task_handle);
    LOOP_ERRMSG(retval != pdPASS, "Could not start lwip eth_int task\n" );


#if XBH_IP4_STATIC
    ip_addr.addr = htonl(XBH_IP4_ADDR);
    netmask.addr = htonl(XBH_IP4_NETMASK);
    gw_addr.addr = 0;
#else
    ip_addr.addr = 0;
    netmask.addr = 0;
    gw_addr.addr = 0;
#endif
    netif_add(&lwip_netif, &ip_addr, &netmask, &gw_addr, NULL, tivaif_init,
            tcpip_input);

    //netif_add sets everything to defaults, so run after netif_add
    netif_set_hostname(&lwip_netif, XBH_HOSTNAME);
    netif_set_status_callback(&lwip_netif, link_status);
    netif_set_default(&lwip_netif);

#if LWIP_IPV6
    lwip_netif.ip6_autoconfig_enabled = 1;
    lwip_netif.output_ip6 = ethip6_output;
    //IPv6, enable linklocal addresses and SLAAC
    netif_create_ip6_linklocal_address(&lwip_netif, 1);
    netif_ip6_addr_set_state((&lwip_netif), 0, IP6_ADDR_TENTATIVE); 
#endif
#if XBH_IP4_STATIC
    netif_set_up(&lwip_netif);
#else
    dhcp_start(&lwip_netif);
#endif
    
#if DEBUG_STACK
    DEBUG_OUT("Stack Usage: %s: %d\n", __PRETTY_FUNCTION__, uxTaskGetStackHighWaterMark(NULL));
#endif
}/*}}}*/
Exemple #14
0
/*!
 *  \brief set ethernet config
 */
static void prvEthernetConfigureInterface(void * param)
{
   struct ip_addr    xIpAddr, xNetMask, xGateway;
   extern err_t      ethernetif_init( struct netif *netif );
   unsigned char MacAddress[6];

   /* Default MAC addr. */
   MacAddress[0] = ETHERNET_CONF_ETHADDR0;
   MacAddress[1] = ETHERNET_CONF_ETHADDR1;
   MacAddress[2] = ETHERNET_CONF_ETHADDR2;
   MacAddress[3] = ETHERNET_CONF_ETHADDR3;
   MacAddress[4] = ETHERNET_CONF_ETHADDR4;
   MacAddress[5] = ETHERNET_CONF_ETHADDR5;

   /* pass the MAC address to MACB module */
   vMACBSetMACAddress( MacAddress );

#if defined(DHCP_USED)
  xIpAddr.addr  = 0;
  xNetMask.addr = 0;
  xNetMask.addr = 0;
#else
  /* Default ip addr. */
  IP4_ADDR( &xIpAddr,ETHERNET_CONF_IPADDR0,ETHERNET_CONF_IPADDR1,ETHERNET_CONF_IPADDR2,ETHERNET_CONF_IPADDR3 );

  /* Default Subnet mask. */
  IP4_ADDR( &xNetMask,ETHERNET_CONF_NET_MASK0,ETHERNET_CONF_NET_MASK1,ETHERNET_CONF_NET_MASK2,ETHERNET_CONF_NET_MASK3 );

  /* Default Gw addr. */
  IP4_ADDR( &xGateway,ETHERNET_CONF_GATEWAY_ADDR0,ETHERNET_CONF_GATEWAY_ADDR1,ETHERNET_CONF_GATEWAY_ADDR2,ETHERNET_CONF_GATEWAY_ADDR3 );
#endif

  /* add data to netif */
  netif_add( &MACB_if, &xIpAddr, &xNetMask, &xGateway, NULL, ethernetif_init, ethernet_input );

  /* make it the default interface */
  netif_set_default( &MACB_if );

  /* Setup callback function for netif status change */
  netif_set_status_callback(&MACB_if, status_callback);

  /* bring it up */
#if defined(DHCP_USED)
  display_print("LwIP: DHCP Started");
  dhcp_start( &MACB_if );
#else
  display_print("LwIP: Static IP Address Assigned");
  netif_set_up( &MACB_if );
#endif
}
void wifi_initial_task() {
  struct netif *sta_if;
  wifi_init(&wifi_config, NULL);
  lwip_tcpip_init(&tcpip_config, WIFI_MODE_STA_ONLY);

  ip_ready = xSemaphoreCreateBinary();

  sta_if = netif_find_by_type(NETIF_TYPE_STA);
  netif_set_status_callback(sta_if, _ip_ready_callback);
  dhcp_start(sta_if);

  xSemaphoreTake(ip_ready, portMAX_DELAY);
  mcs_tcp_init(tcp_callback);
  vTaskDelete(NULL);
}
Exemple #16
0
/**
 *  \brief Set ethernet config.
 */
static void ethernet_configure_interface(void)
{
	struct ip_addr x_ip_addr, x_net_mask, x_gateway;
	extern err_t ethernetif_init(struct netif *netif);

	if(f_ip_config.mode == IP_CONFIG_MODE_DHCP)
	{
		x_ip_addr.addr = 0;
		x_net_mask.addr = 0;
	}
	else
	{
		/* Default ip addr */
		IP4_ADDR(&x_ip_addr, f_ip_config.ip[0], f_ip_config.ip[1],
				f_ip_config.ip[2], f_ip_config.ip[3]);

		/* Default subnet mask */
		IP4_ADDR(&x_net_mask, f_ip_config.mask[0], f_ip_config.mask[1],
				f_ip_config.mask[2], f_ip_config.mask[3]);
		
		/* Default gateway addr */
		IP4_ADDR(&x_gateway, ETHERNET_CONF_GATEWAY_ADDR0,
				ETHERNET_CONF_GATEWAY_ADDR1,
				ETHERNET_CONF_GATEWAY_ADDR2,
				ETHERNET_CONF_GATEWAY_ADDR3);
	}
	
	/* Add data to netif */
	netif_add(&gs_net_if, &x_ip_addr, &x_net_mask, &x_gateway, NULL,
			ethernetif_init, ethernet_input);

	/* Make it the default interface */
	netif_set_default(&gs_net_if);

	/* Setup callback function for netif status change */
	netif_set_status_callback(&gs_net_if, status_callback);

	/* Bring it up */
	if(f_ip_config.mode == IP_CONFIG_MODE_DHCP)
	{
		dhcp_start(&gs_net_if);
	}
	else
	{
		netif_set_up(&gs_net_if);
	}
}
Exemple #17
0
/**
 * \brief Set ethernet config.
 */
static void ethernet_configure_interface(void)
{
	struct ip_addr x_ip_addr, x_net_mask, x_gateway;

	if (g_ip_mode == 2) {
		x_ip_addr.addr = 0;
		x_net_mask.addr = 0;
	} else {
		/** Default ip addr */
		IP4_ADDR(&x_ip_addr, ETHERNET_CONF_IPADDR0, ETHERNET_CONF_IPADDR1,
				ETHERNET_CONF_IPADDR2, ETHERNET_CONF_IPADDR3);
	
		/** Default subnet mask */
		IP4_ADDR(&x_net_mask, ETHERNET_CONF_NET_MASK0, ETHERNET_CONF_NET_MASK1,
				ETHERNET_CONF_NET_MASK2, ETHERNET_CONF_NET_MASK3);
	
		/** Default gateway addr */
		IP4_ADDR(&x_gateway, ETHERNET_CONF_GATEWAY_ADDR0,
				ETHERNET_CONF_GATEWAY_ADDR1,
				ETHERNET_CONF_GATEWAY_ADDR2,
				ETHERNET_CONF_GATEWAY_ADDR3);
	}

	/** Add data to netif */
	if( NULL == netif_add(&gs_net_if, &x_ip_addr, &x_net_mask, &x_gateway, NULL,
			ethernetif_init, ethernet_input) ) {
		TRACE_DEBUG("ERROR");
		while(1);
	}
	/** Make it the default interface */
	netif_set_default(&gs_net_if);

	/** Setup callback function for netif status change */
	netif_set_status_callback(&gs_net_if, status_callback);

	/** Bring it up */
	if (g_ip_mode == 2) {
		/** DHCP mode*/
		if(ERR_OK != dhcp_start(&gs_net_if)) {
			TRACE_DEBUG("ERROR");
			while(1);
		}
	} else {
		/** Static mode*/
		netif_set_up(&gs_net_if);
	}
}
void LWIP_SOCKETS_Driver::TcpipInitDone(void* arg)
{
	struct netif *pNetIf;

	for (int i = 0; i<g_NetworkConfig.NetworkInterfaceCount; i++)
	{
		int interfaceNumber;

		SOCK_NetworkConfiguration *pNetCfg = &g_NetworkConfig.NetworkInterfaces[i];

		/* Bind and Open the Ethernet driver */
		Network_Interface_Bind(i);
		interfaceNumber = Network_Interface_Open(i);

		if (interfaceNumber == SOCK_SOCKET_ERROR)
		{
			DEBUG_HANDLE_SOCKET_ERROR("Network init", FALSE);
			debug_printf("SocketError: %d\n", errno);
			continue;
		}

		g_LWIP_SOCKETS_Driver.m_interfaces[i].m_interfaceNumber = interfaceNumber;

		UpdateAdapterConfiguration(i, SOCK_NETWORKCONFIGURATION_UPDATE_DHCP | SOCK_NETWORKCONFIGURATION_UPDATE_DNS, pNetCfg);

		pNetIf = netif_find_interface(interfaceNumber);

		if (pNetIf)
		{		
			netif_set_link_callback(pNetIf, Link_callback);
			if (netif_is_link_up(pNetIf))
				Link_callback(pNetIf);

			netif_set_status_callback(pNetIf, Status_callback);
			if (netif_is_up(pNetIf))
				Status_callback(pNetIf);

			// default debugger interface
            if (0 == i)
            {
                UINT8* addr = (UINT8*)&pNetIf->ip_addr.addr;
                lcd_printf("\f\n\n\n\n\n\n\nip address: %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3]);
                debug_printf("ip address from interface info: %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3]);
            }
		}
	}
}
/**
  * @brief  Initializes the lwIP stack
  * @param  None
  * @retval None
  */
void Netif_Config(void)
{
    ip_addr_t ipaddr;
    ip_addr_t netmask;
    ip_addr_t gw; 


#if LWIP_DHCP
        ipaddr.addr = 0;
        netmask.addr = 0;
        gw.addr = 0;
#else
        IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
        IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
        IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
    
    
        printf("STATIC IP:%d.%d.%d.%d\r\n",ip4_addr1(&ipaddr), ip4_addr2(&ipaddr),ip4_addr3(&ipaddr),ip4_addr4(&ipaddr));
        printf("STATIC GW:%d.%d.%d.%d\r\n",ip4_addr1(&gw), ip4_addr2(&gw),ip4_addr3(&gw),ip4_addr4(&gw));
        printf("STATIC MASK:%d.%d.%d.%d\r\n",ip4_addr1(&netmask), ip4_addr2(&netmask),ip4_addr3(&netmask),ip4_addr4(&netmask));
#endif

        /* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
                  struct ip_addr *netmask, struct ip_addr *gw,
                  void *state, err_t (* init)(struct netif *netif),
                  err_t (* input)(struct pbuf *p, struct netif *netif))
    
         Adds your network interface to the netif_list. Allocate a struct
        netif and pass a pointer to this structure as the first argument.
        Give pointers to cleared ip_addr structures when using DHCP,
        or fill them with sane numbers otherwise. The state pointer may be NULL.
    
        The init function pointer must point to a initialization function for
        your ethernet netif interface. The following code illustrates it's use.*/
        netif_add(&wireless_netif, &ipaddr, &netmask, &gw, NULL, &wlan_ethernetif_init, &tcpip_input);
 
        /*  Registers the default network interface.*/
       netifapi_netif_common(&wireless_netif, netif_set_default, NULL);
       
#if LWIP_DHCP
       netif_set_status_callback(&wireless_netif, netif_status_callback);
#else
       netifapi_netif_common(&wireless_netif, netif_set_up, NULL);
#endif

}
void cbIP_initPanInterfaceDHCP(
    char* hostname, 
    const cbIP_IPv6Settings * const IPv6Settings, 
    cbIP_interfaceSettings const * const ifConfig, 
    cbIP_statusIndication callback, 
    void* callbackArg)
{
    struct ip_addr ipaddr;
    struct ip_addr netmask;
    struct ip_addr gw;
    struct ip6_addr ip6addr;

    MBED_ASSERT(callback != NULL && hostname != NULL && ifConfig != NULL);

    IP4_ADDR(&gw, 0, 0, 0, 0);
    IP4_ADDR(&ipaddr, 0, 0, 0, 0);
    IP4_ADDR(&netmask, 0, 0, 0, 0);

    memcpy(&ip6addr, &IPv6Settings->linklocal.value, sizeof(ip6addr));

    memcpy(&panIf.ifConfig, ifConfig, sizeof(panIf.ifConfig));

    netif_add(&panIf.hInterface, &ipaddr, &netmask, &gw, &panIf, cb_netif_init, ethernet_input);
    panIf.hInterface.hostname = hostname;
    panIf.callbackArg = callbackArg;
    panIf.hInterface.ip6_autoconfig_enabled = 0;
    if ((ip6addr.addr[0] == 0) && (ip6addr.addr[1] == 0) &&
        (ip6addr.addr[2] == 0) && (ip6addr.addr[3] == 0)) {
        netif_create_ip6_linklocal_address(&panIf.hInterface, 1);
    } else {
        panIf.hInterface.ip6_addr[0] = ip6addr;
    }
    netif_ip6_addr_set_state((&panIf.hInterface), 0, IP6_ADDR_TENTATIVE);

    panIf.statusCallback = callback;
    netif_set_status_callback(&panIf.hInterface, netif_status_callback);

    LWIP_PRINT("Using DHCP\n");
    dhcp_start(&panIf.hInterface);

    cb_uint32 result;
    result = cbBTPAN_registerDataCallback(&_panCallBack);
    MBED_ASSERT(result == cbBTPAN_RESULT_OK);
}
static void ethernet_configure_interface(unsigned char ipAddress[], unsigned char netMask[], unsigned char gateWay[])
{
	struct ip_addr x_ip_addr, x_net_mask, x_gateway;
	extern err_t ethernetif_init(struct netif *netif);

#if defined(DHCP_USED)
	x_ip_addr.addr = 0;
	x_net_mask.addr = 0;
#else
	/* Default ip addr */
	//IP4_ADDR(&x_ip_addr, ETHERNET_CONF_IPADDR0, ETHERNET_CONF_IPADDR1, ETHERNET_CONF_IPADDR2, ETHERNET_CONF_IPADDR3);

	IP4_ADDR(&x_ip_addr, ipAddress[0], ipAddress[1], ipAddress[2], ipAddress[3]);

	/* Default subnet mask */
	//IP4_ADDR(&x_net_mask, ETHERNET_CONF_NET_MASK0, ETHERNET_CONF_NET_MASK1, ETHERNET_CONF_NET_MASK2, ETHERNET_CONF_NET_MASK3);

	IP4_ADDR(&x_net_mask, netMask[0], netMask[1], netMask[2], netMask[3]);

	/* Default gateway addr */
	//IP4_ADDR(&x_gateway, ETHERNET_CONF_GATEWAY_ADDR0, ETHERNET_CONF_GATEWAY_ADDR1, ETHERNET_CONF_GATEWAY_ADDR2, ETHERNET_CONF_GATEWAY_ADDR3);

	IP4_ADDR(&x_gateway, gateWay[0], gateWay[1], gateWay[2], gateWay[3]);
#endif

	/* Add data to netif */
	netif_add(&gs_net_if, &x_ip_addr, &x_net_mask, &x_gateway, NULL,
			ethernetif_init, ethernet_input);

	/* Make it the default interface */
	netif_set_default(&gs_net_if);

	/* Setup callback function for netif status change */
	netif_set_status_callback(&gs_net_if, status_callback);

	/* Bring it up */
#if defined(DHCP_USED)
	printf("LwIP: DHCP Started");
	dhcp_start(&gs_net_if);
#else
//	printf("LwIP: Static IP Address Assigned\r\n");
	netif_set_up(&gs_net_if);
#endif
}
Exemple #22
0
nsapi_error_t LWIP::add_l3ip_interface(L3IP &l3ip, bool default_if, OnboardNetworkStack::Interface **interface_out)
{
#if LWIP_L3IP
    Interface *interface = new (std::nothrow) Interface();
    if (!interface) {
        return NSAPI_ERROR_NO_MEMORY;
    }
    interface->l3ip = &l3ip;
    interface->memory_manager = &memory_manager;
    interface->ppp = false;



    // interface->netif.hwaddr_len = 0; should we set?

    if (!netif_add(&interface->netif,
#if LWIP_IPV4
                   0, 0, 0,
#endif
                   interface, &LWIP::Interface::emac_if_init, ip_input)) {
        return NSAPI_ERROR_DEVICE_ERROR;
    }

    if (default_if) {
        netif_set_default(&interface->netif);
        default_interface = interface;
    }

    netif_set_link_callback(&interface->netif, &LWIP::Interface::netif_link_irq);
    netif_set_status_callback(&interface->netif, &LWIP::Interface::netif_status_irq);

    *interface_out = interface;


    //lwip_add_random_seed(seed); to do?

    return NSAPI_ERROR_OK;

#else
    return NSAPI_ERROR_UNSUPPORTED;

#endif //LWIP_L3IP
}
Exemple #23
0
int lwip_bringup(void)
{
    // Check if we've already connected
    if (lwip_get_ip_address()) {
        return NSAPI_ERROR_PARAMETER;
    }

    // Check if we've already brought up lwip
    if (!lwip_get_mac_address()) {
        // Set up network
        lwip_set_mac_address();

        sys_sem_new(&lwip_tcpip_inited, 0);
        sys_sem_new(&lwip_netif_linked, 0);
        sys_sem_new(&lwip_netif_up, 0);

        tcpip_init(lwip_tcpip_init_irq, NULL);
        sys_arch_sem_wait(&lwip_tcpip_inited, 0);

        memset(&lwip_netif, 0, sizeof lwip_netif);
        netif_add(&lwip_netif, 0, 0, 0, NULL, eth_arch_enetif_init, tcpip_input);
        netif_set_default(&lwip_netif);

        netif_set_link_callback  (&lwip_netif, lwip_netif_link_irq);
        netif_set_status_callback(&lwip_netif, lwip_netif_status_irq);

        eth_arch_enable_interrupts();
    }

    // Zero out socket set
    lwip_arena_init();

    // Connect to the network
    dhcp_start(&lwip_netif);

    // Wait for an IP Address
    u32_t ret = sys_arch_sem_wait(&lwip_netif_up, 15000);
    if (ret == SYS_ARCH_TIMEOUT) {
        return NSAPI_ERROR_DHCP_FAILURE;
    }

    return 0;
}
Exemple #24
0
void 
wl_init_complete_cb(void* ctx) 
{
	struct ctx_server *hs = ctx;
    struct ip_addr ipaddr, netmask, gw;
	wl_err_t wl_status;
	
	if (hs->net_cfg.dhcp_enabled == INIT_IP_CONFIG)
	{
		IP4_ADDR(&gw, 0,0,0,0);
		IP4_ADDR(&ipaddr, 0,0,0,0);
		IP4_ADDR(&netmask, 0,0,0,0);
			
		/* default is dhcp enabled */
		hs->net_cfg.dhcp_enabled = DYNAMIC_IP_CONFIG;
	}

    start_ip_stack(&hs->net_cfg,
                   ipaddr,
                   netmask,
                   gw);
    netif_set_status_callback(hs->net_cfg.netif, ip_status_cb);

    INFO_INIT("Starting CM...\n");
    /* start connection manager */
    wl_status = wl_cm_init(wl_cm_scan_cb, wl_cm_conn_cb, wl_cm_disconn_cb, hs);
    ASSERT(wl_status == WL_SUCCESS, "failed to init wl conn mgr");
    wl_cm_start();

    wl_scan();

    if (initSpi(hs)){
    	WARN("Spi not initialized\n");
    }else
    {
    	initSpiComplete = true;
        AVAIL_FOR_SPI();
    }

    hs->wl_init_complete = 1;
}
/**
  * @brief  Stop lwip service in a certain operation mode.
  * @param[in] uint8_t opmode: the current operation mode.
  * @retval None
  */
void lwip_net_stop(uint8_t opmode)
{
    struct netif *sta_if;
    struct netif *ap_if;

    sta_if = netif_find_by_type(NETIF_TYPE_STA);
    ap_if = netif_find_by_type(NETIF_TYPE_AP);
    switch (opmode) {
        case WIFI_MODE_AP_ONLY:
            dhcpd_stop();
            netif_set_link_down(ap_if);
            break;
        case WIFI_MODE_STA_ONLY:
        case WIFI_MODE_REPEATER:
            netif_set_status_callback(sta_if, NULL);
            dhcp_release(sta_if);
            dhcp_stop(sta_if);
            netif_set_link_down(sta_if);
            break;
    }
}
void start_ethernet(const uint8_t ipAddress[], const uint8_t netMask[], const uint8_t gateWay[], netif_status_callback_fn status_cb)
{
	struct ip_addr x_ip_addr, x_net_mask, x_gateway;
	extern err_t ethernetif_init(struct netif *netif);

	IP4_ADDR(&x_ip_addr, ipAddress[0], ipAddress[1], ipAddress[2], ipAddress[3]);		// set IP address

	if (x_ip_addr.addr == 0)
	{
		x_net_mask.addr = 0;
		x_gateway.addr = 0;
	}
	else
	{
		IP4_ADDR(&x_net_mask, netMask[0], netMask[1], netMask[2], netMask[3]);			// set network mask
		IP4_ADDR(&x_gateway, gateWay[0], gateWay[1], gateWay[2], gateWay[3]);			// set gateway
	}

	/* Add data to netif */
	netif_add(&gs_net_if, &x_ip_addr, &x_net_mask, &x_gateway, NULL, ethernetif_init, ethernet_input);

	/* Make it the default interface */
	netif_set_default(&gs_net_if);

	/* Setup callback function for netif status change */
	netif_set_status_callback(&gs_net_if, status_cb);

	/* Bring it up */
	if (x_ip_addr.addr == 0)
	{
		/* DHCP mode */
		dhcp_start(&gs_net_if);
	}
	else
	{
		/* Static mode */
		netif_set_up(&gs_net_if);
	}
}
static void ethernet_configure_interface(const unsigned char ipAddress[], const unsigned char netMask[], const unsigned char gateWay[])
{
	struct ip_addr x_ip_addr, x_net_mask, x_gateway;
	extern err_t ethernetif_init(struct netif *netif);

	IP4_ADDR(&x_ip_addr, ipAddress[0], ipAddress[1], ipAddress[2], ipAddress[3]);		// set IP address

	if (x_ip_addr.addr == 0)
	{
		x_net_mask.addr = 0;	// not sure this is needed, but the demo program does it
	}
	else
	{
		IP4_ADDR(&x_net_mask, netMask[0], netMask[1], netMask[2], netMask[3]);			// set network mask
	}

	IP4_ADDR(&x_gateway, gateWay[0], gateWay[1], gateWay[2], gateWay[3]);				// set gateway

	/* Add data to netif */
	netif_add(&gs_net_if, &x_ip_addr, &x_net_mask, &x_gateway, NULL, ethernetif_init, ethernet_input);

	/* Make it the default interface */
	netif_set_default(&gs_net_if);

	/* Setup callback function for netif status change */
	netif_set_status_callback(&gs_net_if, ethernet_status_callback);

	/* Bring it up */
	if (x_ip_addr.addr == 0)
	{
		RepRapNetworkMessage("Starting DHCP\n");
		dhcp_start(&gs_net_if);
	}
	else
	{
		RepRapNetworkMessage("Starting network\n");
		netif_set_up(&gs_net_if);
	}
}
Exemple #28
0
void start_ethernet(IPAddress ipAddress, IPAddress netMask, IPAddress gateWay, netif_status_callback_fn status_cb)
{
	struct ip_addr x_ip_addr, x_net_mask, x_gateway;
	extern err_t ethernetif_init(struct netif *netif);

	x_ip_addr.addr = ipAddress.GetV4LittleEndian();

	if (x_ip_addr.addr == 0)
	{
		x_net_mask.addr = 0;
		x_gateway.addr = 0;
	}
	else
	{
		x_net_mask.addr = netMask.GetV4LittleEndian();
		x_gateway.addr = gateWay.GetV4LittleEndian();
	}

	/* Add data to netif */
	netif_add(&gs_net_if, &x_ip_addr, &x_net_mask, &x_gateway, NULL, ethernetif_init, ethernet_input);

	/* Make it the default interface */
	netif_set_default(&gs_net_if);

	/* Setup callback function for netif status change */
	netif_set_status_callback(&gs_net_if, status_cb);

	/* Bring it up */
	if (x_ip_addr.addr == 0)
	{
		/* DHCP mode */
		dhcp_start(&gs_net_if);
	}
	else
	{
		/* Static mode */
		netif_set_up(&gs_net_if);
	}
}
Exemple #29
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 */
}
Exemple #30
0
/**
  * @brief  LwIP_DHCP_Process_Handle
  * @param  None
  * @retval None
  */
void LwIP_DHCP_task(void * pvParameters)
{
	struct ip_addr ipaddr;
	struct ip_addr netmask;
	struct ip_addr gw;
	uint32_t IPaddress;
	uint8_t iptab[4];
	uint8_t iptxt[20];
	uint8_t DHCP_state;  
	DHCP_state = DHCP_START;
	bool terminate=false;

	netif_set_status_callback(&xnetif, netif_status_callback);

	LwIP_Init();

	while (!terminate)
	{
		switch (DHCP_state)
		{
			case DHCP_START:
				{
					dhcp_start(&xnetif);
					IPaddress = 0;
					DHCP_state = DHCP_WAIT_ADDRESS;
					syslog(SYSTEM_LVL,true,"DHCP_START");
				}
				break;
			case DHCP_WAIT_ADDRESS:
				{
					IPaddress = xnetif.ip_addr.addr;	/* Read the new IP address */

					if (IPaddress!=0) 
					{
						DHCP_state = DHCP_ADDRESS_ASSIGNED;	
                        
						/* Stop DHCP */
						dhcp_stop(&xnetif);
										
						iptab[0] = (uint8_t)(IPaddress >> 24);
						iptab[1] = (uint8_t)(IPaddress >> 16);
						iptab[2] = (uint8_t)(IPaddress >> 8);
						iptab[3] = (uint8_t)(IPaddress);

						sprintf((char*)iptxt, "  %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]);  
						syslog(SYSTEM_LVL,true,"DHCP_WAIT_ADDRESS reply %s",iptxt);
					}
					else
					{
						/* DHCP timeout */
						if (xnetif.dhcp->tries > MAX_DHCP_TRIES)
						{
							DHCP_state = DHCP_TIMEOUT;

							/* Stop DHCP */
							dhcp_stop(&xnetif);

							/* Static address used */
							IP4_ADDR(&ipaddr, IP_ADDR0 ,IP_ADDR1 , IP_ADDR2 , IP_ADDR3 );
							IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
							IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
							netif_set_addr(&xnetif, &ipaddr , &netmask, &gw);

							syslog(SYSTEM_LVL,true,"DHCP_TIMEOUT");

							iptab[0] = IP_ADDR3;
							iptab[1] = IP_ADDR2;
							iptab[2] = IP_ADDR1;
							iptab[3] = IP_ADDR0;

							sprintf((char*)iptxt, "  %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]); 
							syslog(SYSTEM_LVL,true,"DHCP_TIMEOUT activating static ip %s",iptxt);
							netif_status_callback(&xnetif);
						}
					}
				}
				break;
			case DHCP_ADDRESS_ASSIGNED:
				syslog(SYSTEM_LVL,true,"DHCP_ADDRESS_ASSIGNED");
                netif_status_callback(&xnetif);
				terminate=true;
				break;
			default: 
				break;
		}