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; }
/*---------------------------------------------------------------------------* * 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; }
void vBasicWEBServer( void *pvParameters ) { struct netconn *pxHTTPListener, *pxNewConnection; struct ip_addr xIpAddr, xNetMast, xGateway; static struct netif fec523x_if; extern err_t ethernetif_init(struct netif *netif); /* Parameters are not used - suppress compiler error. */ ( void )pvParameters; vlwIPInit(); /* Create and configure the FEC interface. */ IP4_ADDR( &xIpAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 ); IP4_ADDR( &xNetMast, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 ); IP4_ADDR( &xGateway, configGW_ADDR0, configGW_ADDR1, configGW_ADDR2, configGW_ADDR3 ); netif_add( &fec523x_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init, tcpip_input ); /* make it the default interface */ netif_set_default( &fec523x_if ); /* bring it up */ netif_set_up( &fec523x_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 ); } } } }
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; }
static err_t eth_netif_device_init(struct netif *netif) { struct eth_device *ethif; ethif = (struct eth_device*)netif->state; if (ethif != NULL) { rt_device_t device; /* get device object */ device = (rt_device_t) ethif; if (rt_device_init(device) != RT_EOK) { return ERR_IF; } /* copy device flags to netif flags */ netif->flags = ethif->flags; /* set default netif */ if (netif_default == NULL) netif_set_default(ethif->netif); #if LWIP_DHCP if (ethif->flags & NETIF_FLAG_DHCP) { /* if this interface uses DHCP, start the DHCP client */ dhcp_start(ethif->netif); } else #endif { /* set interface up */ netif_set_up(ethif->netif); } #ifdef LWIP_NETIF_LINK_CALLBACK netif_set_link_up(ethif->netif); #endif return ERR_OK; } return ERR_IF; }
/* 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, ðernetif_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 */ }
/** * @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, ðernetif_init, ðernet_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); }
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 }
/* 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; }
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); }
static void tcpip_init_done(void* arg) { #if DEBUG kprintf(LOG, "[%d] tcpip: initialized in %d MS\n", sys_getpid(), timer_getms() - (uint32_t) arg); #else (void) arg; #endif struct netif* lo = netif_find("lo0"); if(likely(lo)) { netif_set_up(lo); netif_set_default(lo); } else kprintf(WARN, "netif: Loopback interface not found\n"); lwip_socket_init(); }
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); }
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 }
static err_t eth_netif_device_init(struct netif *netif) { struct eth_device *ethif; ethif = (struct eth_device*)netif->state; if (ethif != RT_NULL) { rt_device_t device; /* get device object */ device = (rt_device_t) ethif; if (rt_device_init(device) != RT_EOK) { return ERR_IF; } /* copy device flags to netif flags */ netif->flags = (ethif->flags & 0xff); /* set default netif */ if (netif_default == RT_NULL) netif_set_default(ethif->netif); #if LWIP_DHCP /* set interface up */ netif_set_up(ethif->netif); /* if this interface uses DHCP, start the DHCP client */ dhcp_start(ethif->netif); #else /* set interface up */ netif_set_up(ethif->netif); #endif if (!(ethif->flags & ETHIF_LINK_PHYUP)) { /* set link_up for this netif */ netif_set_link_up(ethif->netif); } return ERR_OK; } return ERR_IF; }
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)); }
/*! * @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; }
/** * Remove a network interface from the list of lwIP netifs. * * @param netif the network interface to remove */ void netif_remove(struct netif *netif) { if (netif == NULL) { return; } #if LWIP_IGMP /* stop IGMP processing */ if (netif->flags & NETIF_FLAG_IGMP) { igmp_stop(netif); } #endif /* LWIP_IGMP */ if (netif_is_up(netif)) { /* set netif down before removing (call callback function) */ netif_set_down(netif); } snmp_delete_ipaddridx_tree(netif); /* is it the first netif? */ if (netif_list == netif) { netif_list = netif->next; } else { /* look for netif further down the list */ struct netif * tmpNetif; for (tmpNetif = netif_list; tmpNetif != NULL; tmpNetif = tmpNetif->next) { if (tmpNetif->next == netif) { tmpNetif->next = netif->next; break; } } if (tmpNetif == NULL) return; /* we didn't find any netif today */ } snmp_dec_iflist(); /* this netif is default? */ if (netif_default == netif) { /* reset default netif */ netif_set_default(NULL); } LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") ); }
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); }
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 }
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; }
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; }
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); }
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; }
/* 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); }
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 }
static inline int InitLWIPStack(struct ip_addr *IP, struct ip_addr *NM, struct ip_addr *GW){ static struct NetManNetProtStack stack={ &LinkStateUp, &LinkStateDown, &AllocRxPacket, &FreeRxPacket, &EnQRxPacket, &FlushInputQueue }; InitializeLWIP(); netif_add(&NIF, IP, NM, GW, &NIF, &SMapIFInit, tcpip_input); netif_set_default(&NIF); NetManRegisterNetworkStack(&stack); netif_set_up(&NIF); return 0; }
int main(void) #endif { ip_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw; app_low_level_init(); OSA_Init(); LWIP_DEBUGF(PING_DEBUG,("TCP/IP initializing...\r\n")); tcpip_init(NULL,NULL); LWIP_DEBUGF(PING_DEBUG,("TCP/IP initialized.\r\n")); 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, tcpip_input); netif_set_default(&fsl_netif0); ping_init(); }
/********************************************************************************************************* ** 函数名称: __rtSetGwCallback ** 功能描述: 设置网络接口的网关(在 TCPIP 上下文中执行) ** 输 入 : pipaddrGw 网关地址 ** uiGwFlags 网关设置属性 ** pcNetifName 网络接口名 ** 输 出 : ERROR_NONE ** 全局变量: ** 调用模块: *********************************************************************************************************/ static INT __rtSetGwCallback (ip_addr_t *pipaddrGw, UINT uiGwFlags, CPCHAR pcNetifName) { #define LW_RT_GW_FLAG_SET 0x1 #define LW_RT_GW_FLAG_DEFAULT 0x2 struct netif *pnetif = netif_find((PCHAR)pcNetifName); if (pnetif) { if (uiGwFlags & LW_RT_GW_FLAG_SET) { netif_set_gw(pnetif, pipaddrGw); } if (uiGwFlags & LW_RT_GW_FLAG_DEFAULT) { netif_set_default(pnetif); } return (ERROR_NONE); } else { _ErrorHandle(ENXIO); return (PX_ERROR); } }
/******************************************************************************** * Name: * netif_proto_init * * Description: * the network card init call low_level_init() * * Parameter: * netif:struct for network card * * Return: * the status of init ********************************************************************************/ static void tcpip_init_done(void *arg) { #if LWIP_IPV4 ip4_addr_t ipaddr, netmask, gw; memset(&ipaddr, 0, sizeof(ipaddr)); memset(&netmask, 0, sizeof(netmask)); memset(&gw, 0, sizeof(gw)); netif_add(&lwip_netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input); #endif #if LWIP_IPV6 #if !LWIP_IPV4 netif_add(&lwip_netif, NULL, ethernetif_init, tcpip_input); #endif netif_create_ip6_linklocal_address(&lwip_netif, 1); lwip_netif.ip6_autoconfig_enabled = 1; #endif netif_set_default(&lwip_netif); netif_set_up(&lwip_netif); }
void net_init(void) { memset(&ipaddr, 0, sizeof(ipaddr)); memset(&netmask, 0, sizeof(ipaddr)); memset(&gw, 0, sizeof(ipaddr)); printf("Initializing network...\n"); lwip_init(); printf("lwIP Initialized\n"); netif_add(ð, &ipaddr, &netmask, &gw, NULL, gelicif_init, ethernet_input); netif_set_default(ð); netif_set_up(ð); printf("Ethernet interface initialized\n"); printf("Starting DHCP\n"); dhcp_start(ð); u64 now = gettb(); #if LWIP_TCP last_tcp_time = now; #endif last_arp_time = last_dhcp_coarse_time = last_dhcp_fine_time = now; }