Пример #1
0
static void init_lwip(void)
{
	lwip_init();
	tcp_mem_free(lwip_free_payload);

	/* setting the IP address */
	IP4_ADDR(&ip, 10,0,2,8);
	IP4_ADDR(&gw, 10,0,1,1);
	/* IP4_ADDR(&ip, 192,168,1,128); */
	/* IP4_ADDR(&gw, 192,168,1,1); */
	IP4_ADDR(&mask, 255,255,255,0);
	
	netif_add(&cos_if, &ip, &mask, &gw, NULL, cos_if_init, ip_input);
	netif_set_default(&cos_if);
	netif_set_up(&cos_if);
}
Пример #2
0
/**
 * Call netif_add() inside the tcpip_thread context.
 */
void
do_netifapi_netif_add( struct netifapi_msg_msg *msg)
{
  if (!netif_add( msg->netif,
                  msg->msg.add.ipaddr,
                  msg->msg.add.netmask,
                  msg->msg.add.gw,
                  msg->msg.add.state,
                  msg->msg.add.init,
                  msg->msg.add.input)) {
    msg->err = ERR_IF;
  } else {
    msg->err = ERR_OK;
  }
  TCPIP_NETIFAPI_ACK(msg);
}
Пример #3
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);
	}
}
Пример #4
0
struct netif *
eagle_lwip_if_alloc(struct myif_state *state, u8_t hw[6], ip_addr_t *ips)
{
    struct ETSEventTag *queue;
    struct netif *myif;
    ip_addr_t ipaddr = ips[0];
    ip_addr_t netmask = ips[1];
    ip_addr_t gw = ips[2];

    if (state->myif == NULL) {
        myif = (void *)os_zalloc(sizeof(struct netif));
    }

    myif->state = state;
    myif->name[0] = 'e';
    myif->name[1] = 'w';
    myif->linkoutput = ieee80211_output_pbuf;
    myif->output = etharp_output;
    ets_memcpy(myif->hwaddr, hw, 6);

    queue = (void *) os_malloc(sizeof(struct ETSEventTag) * QUEUE_LEN);

    if (state->dhcps_if == 0) {
#if LWIP_NETIF_HOSTNAME
#ifdef LWIP_NETIF_HOSTNAME_PREFIX
        myif->hostname = os_malloc(sizeof(LWIP_NETIF_HOSTNAME_PREFIX)+10);
        os_sprintf(myif->hostname, "%s%02x%02x%02x", LWIP_NETIF_HOSTNAME_PREFIX,
                myif->hwaddr[3], myif->hwaddr[4], myif->hwaddr[5]);
#endif
#endif

        ets_task(task_if0, TASK_IF0_PRIO, queue, QUEUE_LEN);
    } else {
        netif_set_addr(myif, &ipaddr, &netmask, &gw);
        if (dhcps_flag != 0) {
            dhcps_start((struct ip_info *)ips);
            os_printf("dhcp server start:(ip:%08x,mask:%08x,gw:%08x)\n",
                    ipaddr.addr, netmask.addr, gw.addr);
        }

        ets_task(task_if1, TASK_IF1_PRIO, queue, QUEUE_LEN);
    }

    netif_add(myif, &ipaddr, &netmask, &gw, state, init_fn, ethernet_input);

    return myif;
}
Пример #5
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);
	}
}
/**
  * @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

}
Пример #7
0
/*---------------------------------------------------------------------------*
 * Routine:  IStartup
 *---------------------------------------------------------------------------*
 * Description:
 *      Start up the Redpine module
 * Inputs:
 *      void *aWorkspace -- Workspace
 * Outputs:
 *      T_uezError -- Error code
 *---------------------------------------------------------------------------*/
static T_uezError IStartup(
    T_Network_lwIP_Workspace *p,
    T_uezNetworkSettings *aSettings)
{
    extern err_t ethernetif_init(struct netif *netif);
    T_uezError error = UEZ_ERROR_NONE;
    struct ip_addr xIpAddr, xNetMast, xGateway;

    // Only support infrastructure network types
    if (aSettings->iNetworkType != UEZ_NETWORK_TYPE_INFRASTRUCTURE)
        return UEZ_ERROR_INCORRECT_TYPE;

    tcpip_init(NULL, NULL);

    /* Create and configure the EMAC interface. */
    IP4_ADDR(&xIpAddr, aSettings->iIPAddress.v4[0],
             aSettings->iIPAddress.v4[1], aSettings->iIPAddress.v4[2],
             aSettings->iIPAddress.v4[3]);
    IP4_ADDR(&xNetMast, aSettings->iSubnetMask.v4[0],
             aSettings->iSubnetMask.v4[1], aSettings->iSubnetMask.v4[2],
             aSettings->iSubnetMask.v4[3]);
    IP4_ADDR(&xGateway, aSettings->iGatewayAddress.v4[0],
             aSettings->iGatewayAddress.v4[1], aSettings->iGatewayAddress.v4[2],
             aSettings->iGatewayAddress.v4[3]);

    /* uEZ v2.04 -- The MAC address is now passed into via the Network Settings
     *              instead of using a confusing callback. */
    p->EMAC_if.hwaddr_len_padding = 6;
    p->EMAC_if.hwaddr[0] = aSettings->iMACAddress.v4[0];
    p->EMAC_if.hwaddr[1] = aSettings->iMACAddress.v4[1];
    p->EMAC_if.hwaddr[2] = aSettings->iMACAddress.v4[2];
    p->EMAC_if.hwaddr[3] = aSettings->iMACAddress.v4[3];
    p->EMAC_if.hwaddr[4] = aSettings->iMACAddress.v4[4];
    p->EMAC_if.hwaddr[5] = aSettings->iMACAddress.v4[5];

    netif_add(&p->EMAC_if, &xIpAddr, &xNetMast, &xGateway, NULL,
              ethernetif_init, tcpip_input);

    /* make it the default interface */
    netif_set_default(&p->EMAC_if);

    /* bring it up */
    netif_set_up(&p->EMAC_if);

    return error;
}
Пример #8
0
static inline int SMapInit(IPAddr IP, IPAddr NM, IPAddr GW, int argc, char *argv[])
{
	if(smap_init(argc, argv)!=0)
	{
		return	0;
	}
	dbgprintf("SMapInit: SMap initialized\n");

	netif_add(&NIF,&IP,&NM,&GW,NULL,&SMapIFInit,tcpip_input);
	netif_set_default(&NIF);
	netif_set_up(&NIF);
	dbgprintf("SMapInit: NetIF added to ps2ip\n");

	//Return 1 (true) to indicate success.

	return	1;
}
Пример #9
0
int AT91_EMAC_LWIP_Driver::Open(int index)
{
    /* Network interface variables */
    struct ip_addr ipaddr, subnetmask, gateway;
    struct netif *pNetIF;
    int len;
    const SOCK_NetworkConfiguration *iface;

    /* Apply network configuration */
    iface = &g_NetworkConfig.NetworkInterfaces[index];

    len = g_AT91_EMAC_NetIF.hwaddr_len;
    if(len == 0 || iface->macAddressLen < len)
    {
        len = iface->macAddressLen;
        g_AT91_EMAC_NetIF.hwaddr_len = len;
    }
    memcpy(g_AT91_EMAC_NetIF.hwaddr, iface->macAddressBuffer, len);

    ipaddr.addr = iface->ipaddr;
    gateway.addr = iface->gateway;
    subnetmask.addr = iface->subnetmask;

    // PHY Power Up
    CPU_GPIO_EnableOutputPin(g_AT91_EMAC_LWIP_Config.PHY_PD_GPIO_Pin, FALSE);

    // Enable Interrupt
    CPU_INTC_ActivateInterrupt(AT91C_ID_EMAC, (HAL_CALLBACK_FPN)AT91_EMAC_LWIP_interrupt, &g_AT91_EMAC_NetIF);

    /* Initialize the continuation routine for the driver interrupt and receive */    
    InitContinuations( pNetIF );

    pNetIF = netif_add( &g_AT91_EMAC_NetIF, &ipaddr, &subnetmask, &gateway, NULL, AT91_EMAC_ethhw_init, ethernet_input );

    netif_set_default( pNetIF );

    LwipNetworkStatus = dm9161_lwip_GetLinkStatus( );
    if (LwipNetworkStatus)
    {
        netif_set_up( pNetIF );
    }
    /* Initialize the continuation routine for the driver interrupt and receive */    
    InitContinuations( pNetIF );

    return g_AT91_EMAC_NetIF.num;
}
Пример #10
0
void vBasicWEBServer( void *pvParameters )
{
struct netconn *pxHTTPListener, *pxNewConnection;
struct ip_addr xIpAddr, xNetMast, xGateway;
extern err_t ethernetif_init( struct netif *netif );
static struct netif EMAC_if;

	/* Parameters are not used - suppress compiler error. */
	( void ) pvParameters;


	/* Create and configure the EMAC interface. */
	IP4_ADDR(&xIpAddr,emacIPADDR0,emacIPADDR1,emacIPADDR2,emacIPADDR3);
	IP4_ADDR(&xNetMast,emacNET_MASK0,emacNET_MASK1,emacNET_MASK2,emacNET_MASK3);
	IP4_ADDR(&xGateway,emacGATEWAY_ADDR0,emacGATEWAY_ADDR1,emacGATEWAY_ADDR2,emacGATEWAY_ADDR3);
	netif_add(&EMAC_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init, tcpip_input);

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

	/* bring it up */
    netif_set_up(&EMAC_if);

	/* Create a new tcp connection handle */

 	pxHTTPListener = netconn_new( NETCONN_TCP );
	netconn_bind(pxHTTPListener, NULL, webHTTP_PORT );
	netconn_listen( pxHTTPListener );

	/* Loop forever */
	for( ;; )
	{
		/* Wait for connection. */
		pxNewConnection = netconn_accept(pxHTTPListener);

		if(pxNewConnection != NULL)
		{
			/* Service connection. */
			vProcessConnection( pxNewConnection );
			while( netconn_delete( pxNewConnection ) != ERR_OK )
			{
				vTaskDelay( webSHORT_DELAY );
			}
		}
	}
}
Пример #11
0
/* ethernetif APIs */
rt_err_t eth_device_init(struct eth_device* dev, const char* name)
{
	struct netif* pnetif;
	/* allocate memory */
	pnetif = (struct netif*) rt_malloc (sizeof(struct netif));
	if (pnetif == RT_NULL)
	{
		rt_kprintf("malloc netif failed\n");
		return -RT_ERROR;
	}
	rt_memset(pnetif, 0, sizeof(struct netif));


	/* set netif */
	dev->netif = pnetif;
	/* register to rt-thread device manager */
	rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
	dev->parent.type = RT_Device_Class_NetIf;
	rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO);


	/* add netif to lwip */
	/* NOTE: eth_init will be called back by netif_add, we should put some initialization
	         code to eth_init(). See include/lwip/netif.h line 97 */
	eth_dev = dev;
	if (netif_add(pnetif, IP_ADDR_ANY, IP_ADDR_BROADCAST, IP_ADDR_ANY, dev,
		ethernetif_init, ethernet_input) == RT_NULL)
	{
		/* failed, unregister device and free netif */
		rt_device_unregister(&(dev->parent));
		rt_free(pnetif);
		eth_dev = RT_NULL;
		return -RT_ERROR;
	}
	eth_dev = RT_NULL;

	netif_set_default(pnetif);

	/* We bring up the netif here cause we still don't have a call back function
	which indicates the ethernet interface status from the ethernet driver. */
	netif_set_up(pnetif);
	netif_set_link_up(pnetif);

	return RT_EOK;
}
Пример #12
0
void start_networking(void)
{
  struct ip_addr ipaddr = { htonl(IF_IPADDR) };
  struct ip_addr netmask = { htonl(IF_NETMASK) };
  struct ip_addr gw = { 0 };
  char *ip = NULL;

#ifdef CONFIG_PRINT
  tprintk("Waiting for network.\n");
#endif

  dev = init_netfront(NULL, NULL, rawmac, &ip);

  if (ip) {
    ipaddr.addr = inet_addr(ip);
    if (IN_CLASSA(ntohl(ipaddr.addr)))
      netmask.addr = htonl(IN_CLASSA_NET);
    else if (IN_CLASSB(ntohl(ipaddr.addr)))
      netmask.addr = htonl(IN_CLASSB_NET);
    else if (IN_CLASSC(ntohl(ipaddr.addr)))
      netmask.addr = htonl(IN_CLASSC_NET);
    else
      tprintk("Strange IP %s, leaving netmask to 0.\n", ip);
  }
  tprintk("IP %x netmask %x gateway %x.\n",
          ntohl(ipaddr.addr), ntohl(netmask.addr), ntohl(gw.addr));

#ifdef CONFIG_PRINT
  tprintk("TCP/IP bringup begins.\n");
#endif

  netif = xmalloc(struct netif);
  tcpip_init(tcpip_bringup_finished, netif);

  netif_add(netif, &ipaddr, &netmask, &gw, rawmac,
            netif_netfront_init, ip_input);
  netif_set_default(netif);
  netif_set_up(netif);

  down(&tcpip_is_up);

#ifdef CONFIG_FRONT
    tprintk("Network is ready.\n");
#endif
}
Пример #13
0
/* init function */
void MX_LWIP_Init(void)
{
  IP_ADDRESS[0] = 192;
  IP_ADDRESS[1] = 168;
  IP_ADDRESS[2] = 203;
  IP_ADDRESS[3] = 36;
  NETMASK_ADDRESS[0] = 255;
  NETMASK_ADDRESS[1] = 255;
  NETMASK_ADDRESS[2] = 255;
  NETMASK_ADDRESS[3] = 0;
  GATEWAY_ADDRESS[0] = 192;
  GATEWAY_ADDRESS[1] = 168;
  GATEWAY_ADDRESS[2] = 203;
  GATEWAY_ADDRESS[3] = 2;
   
  tcpip_init( NULL, NULL );	
 
  IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]);
  IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1] , NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]);
  IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]);  
  

  /* add the network interface */
  netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);
 
 
  /*  Registers the default network interface */
  netif_set_default(&gnetif);

  if (netif_is_link_up(&gnetif))
  {
    /* When the netif is fully configured this function must be called */
    netif_set_up(&gnetif);
  }
  else
  {
    /* When the netif link is down this function must be called */
       netif_set_down(&gnetif);
  }  
  

/* USER CODE BEGIN 3 */

/* USER CODE END 3 */
}
Пример #14
0
/**
  * @brief  Initializes the lwIP stack
  * @param  None
  * @retval None
  */
void LwIP_Init(void)
{
  struct ip_addr ipaddr;
  struct ip_addr netmask;
  struct ip_addr gw;

  /* Initializes the dynamic memory heap defined by MEM_SIZE.*/
  mem_init();

  /* Initializes the memory pools defined by MEMP_NUM_x.*/
  memp_init();

#ifdef USE_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);
  
  /* Deliver static IP complete call */
  LwIP_static_done((IP_ADDR0 << 24) | (IP_ADDR1 << 16) | (IP_ADDR2 << 8) | IP_ADDR3);
#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(&netif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);

  /*  Registers the default network interface.*/
  netif_set_default(&netif);

  /*  When the netif is fully configured this function must be called.*/
  netif_set_up(&netif);
}
Пример #15
0
static void
lwip_init(struct netif *nif, void *if_state,
	  uint32_t init_addr, uint32_t init_mask, uint32_t init_gw)
{
	struct ip_addr ipaddr, netmask, gateway;
	ipaddr.addr  = init_addr;
	netmask.addr = init_mask;
	gateway.addr = init_gw;

	if (0 == netif_add(nif, &ipaddr, &netmask, &gateway,
			   if_state,
			   jif_init,
			   ip_input))
		panic("lwip_init: error in netif_add\n");

	netif_set_default(nif);
	netif_set_up(nif);
}
Пример #16
0
static void network_init(void)
{
    struct ip4_addr local_ip;
    struct ip4_addr netmask;
    struct ip4_addr gateway_ip;

    init_macadr();
    fsip_or_default(&local_ip, "ip", 192, 168, 0, 42);
    fsip_or_default(&netmask, "netmask", 255, 255, 255, 0);
    fsip_or_default(&gateway_ip, "gateway", 192, 168, 0, 1);

    lwip_init();

    netif_add(&netif, &local_ip, &netmask, &gateway_ip, 0, liteeth_init, ethernet_input);
    netif_set_default(&netif);
    netif_set_up(&netif);
    netif_set_link_up(&netif);
}
Пример #17
0
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
}
Пример #18
0
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);
}
Пример #19
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
}
Пример #20
0
VOID
TCPRegisterInterface(PIP_INTERFACE IF)
{
    struct ip_addr ipaddr;
    struct ip_addr netmask;
    struct ip_addr gw;
    
    gw.addr = 0;
    ipaddr.addr = 0;
    netmask.addr = 0;
    
    IF->TCPContext = netif_add(IF->TCPContext, 
                               &ipaddr,
                               &netmask,
                               &gw,
                               IF,
                               TCPInterfaceInit,
                               tcpip_input);
}
Пример #21
0
STATIC void wiznet5k_lwip_init(wiznet5k_obj_t *self) {
    ip_addr_t ipconfig[4];
    ipconfig[0].addr = 0;
    ipconfig[1].addr = 0;
    ipconfig[2].addr = 0;
    ipconfig[3].addr = 0;
    netif_add(&self->netif, &ipconfig[0], &ipconfig[1], &ipconfig[2], self, wiznet5k_netif_init, ethernet_input);
    self->netif.name[0] = 'e';
    self->netif.name[1] = '0';
    netif_set_default(&self->netif);
    dns_setserver(0, &ipconfig[3]);
    dhcp_set_struct(&self->netif, &self->dhcp_struct);
    // Setting NETIF_FLAG_UP then clearing it is a workaround for dhcp_start and the
    // LWIP_DHCP_CHECK_LINK_UP option, so that the DHCP client schedules itself to
    // automatically start when the interface later goes up.
    self->netif.flags |= NETIF_FLAG_UP;
    dhcp_start(&self->netif);
    self->netif.flags &= ~NETIF_FLAG_UP;
}
Пример #22
0
/*!
 * @brief main function
 */
int main(void)
{
  ip_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw;

  app_low_level_init();
  OSA_Init();
  lwip_init();

  IP4_ADDR(&fsl_netif0_ipaddr, 192,168,2,102);
  IP4_ADDR(&fsl_netif0_netmask, 255,255,255,0);
  IP4_ADDR(&fsl_netif0_gw, 192,168,2,100);
  netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, NULL, ethernetif_init, ethernet_input);
  netif_set_default(&fsl_netif0);
  netif_set_up(&fsl_netif0);

  ping_init();

  return 0;
}
Пример #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;
}
Пример #24
0
int
main(int argc, char **argv)
{
        struct netif netif;

        /* startup defaults (may be overridden by one or more opts). this is
         * hard-coded v4 even in presence of v6, which does auto-discovery and
         * should thus wind up with an address of fe80::12:34ff:fe56:78ab%tap0
         * */
        IP4_ADDR(&gw, 192,168,113,1);
        IP4_ADDR(&ipaddr, 192,168,113,2);
        IP4_ADDR(&netmask, 255,255,255,0);

        lwip_init();

        printf("TCP/IP initialized.\n");

        netif_add(&netif, &ipaddr, &netmask, &gw, NULL, tapif_init, ethernet_input);
        netif.flags |= NETIF_FLAG_ETHARP;
        netif_set_default(&netif);
        netif_set_up(&netif);
#if LWIP_IPV6
        netif_create_ip6_linklocal_address(&netif, 1);
#endif

        /* start applications here */

        server_coap_init();

        printf("Applications started.\n");


        while (1) {
                /* poll netif, pass packet to lwIP */
                tapif_select(&netif);

                sys_check_timeouts();

                server_coap_poll();
        }

        return 0;
}
Пример #25
0
static void
tcpip_init_done(void *arg)
{
  ip_addr_t ipaddr, netmask, gateway;
  sys_sem_t *sem;
  sem = arg;

  /*
    CHANGE THESE to suit your own network configuration:
  */
  IP4_ADDR(&gateway, 192,168,1,1);
  IP4_ADDR(&ipaddr, 192,168,1,2);
  IP4_ADDR(&netmask, 255,255,255,0);
  
  netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gateway, NULL, tapif_init,
			      tcpip_input));

  sys_sem_signal(sem);
}
Пример #26
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);
}
Пример #27
0
/**
 * Call netif_add() inside the tcpip_thread context.
 */
static err_t
netifapi_do_netif_add(struct tcpip_api_call_data *m)
{
  struct netifapi_msg *msg = (struct netifapi_msg*)m;
  
  if (!netif_add( msg->netif,
#if LWIP_IPV4
                  API_EXPR_REF(msg->msg.add.ipaddr),
                  API_EXPR_REF(msg->msg.add.netmask),
                  API_EXPR_REF(msg->msg.add.gw),
#endif /* LWIP_IPV4 */
                  msg->msg.add.state,
                  msg->msg.add.init,
                  msg->msg.add.input)) {
    return ERR_IF;
  } else {
    return ERR_OK;
  }
}
Пример #28
0
void _init(void){
  struct ip_addr ipaddr, netmask, gateway;
  sys_sem_t sem;

  sem = sys_sem_new(0);
  tcpip_init(tcpip_init_done, &sem);
  sys_sem_wait(sem);
  sys_sem_free(sem);
  
 /*
    CHANGE THESE to suit your own network configuration:
  */
  IP4_ADDR(&gateway, 192,168,1,1);
  IP4_ADDR(&ipaddr, 192,168,1,2);
  IP4_ADDR(&netmask, 255,255,255,0);
  
  netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gateway, NULL, tapif_init,
			      tcpip_input));
}
void LwipNetInterface::ipStackInitDone(void *pData) {

	LwipNetInterface* lwipInterface;

	lwipInterface = (LwipNetInterface*) pData;

	LWIP_PLATFORM_DIAG(("TCP/IP stack init done\n"));

	LWIP_PLATFORM_DIAG(("netif= %p\n", &lwipInterface->netif));

	netif_set_default(
			netif_add(&lwipInterface->netif, &lwipInterface->ipaddr,
					&lwipInterface->netmask, &lwipInterface->gateway, NULL,
					tapif_init, tcpip_input));

	LWIP_PLATFORM_DIAG(("Signaling semaphore\n"));
	sys_sem_signal(&lwipInterface->syncSem);

}
Пример #30
0
void resume_networking(int cancelled)
{
  //struct netif *netif;
  struct ip_addr ipaddr = { htonl(IF_IPADDR) };
  struct ip_addr netmask = { htonl(IF_NETMASK) };
  struct ip_addr gw = { htonl(0xc0a87a01) };
  char *ip = NULL;

#ifdef CONFIG_PRINT
  tprintk("Waiting for network.\n");
#endif

  dev = init_netfront(NULL, NULL, rawmac, &ip);
  if(!cancelled){
    if (ip) {
        ipaddr.addr = inet_addr(ip);
        if (IN_CLASSA(ntohl(ipaddr.addr)))
            netmask.addr = htonl(IN_CLASSA_NET);
        else if (IN_CLASSB(ntohl(ipaddr.addr)))
            netmask.addr = htonl(IN_CLASSB_NET);
        else if (IN_CLASSC(ntohl(ipaddr.addr)))
            netmask.addr = htonl(IN_CLASSC_NET);
        else
            tprintk("Strange IP %s, leaving netmask to 0.\n", ip);
    }
    tprintk("IP %x netmask %x gateway %x.\n",
            ntohl(ipaddr.addr), ntohl(netmask.addr), ntohl(gw.addr));

    netif = xmalloc(struct netif);

    netif_add(netif, &ipaddr, &netmask, &gw, rawmac,
              netif_netfront_init, ip_input);
    netif_set_default(netif);
    netif_set_up(netif);

    down(&tcpip_is_up);
  }

#ifdef CONFIG_SUSPEND
    tprintk("TCP/IP bringup begins.\n");
#endif
}