/** * @brief This function notify user about link status changement. * @param netif: the network interface * @retval None */ void ethernetif_notify_conn_changed(struct netif *netif) { struct ip_addr ipaddr; struct ip_addr netmask; struct ip_addr gw; if(netif_is_link_up(netif)) { #ifdef USE_DHCP #ifdef USE_LCD LCD_UsrLog ("The network cable is now connected \n"); #else BSP_LED_Off(LED2); BSP_LED_On(LED1); #endif /* USE_LCD */ /* Update DHCP state machine */ DHCP_state = DHCP_START; #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); #ifdef USE_LCD uint8_t iptxt[20]; sprintf((char*)iptxt, "%d.%d.%d.%d", IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3); LCD_UsrLog ("The network cable is now connected \n"); LCD_UsrLog ("Static IP address: %s\n", iptxt); #else BSP_LED_Off(LED2); BSP_LED_On(LED1); #endif /* USE_LCD */ #endif /* USE_DHCP */ netif_set_addr(netif, &ipaddr , &netmask, &gw); /* When the netif is fully configured this function must be called.*/ netif_set_up(netif); } else { #ifdef USE_DHCP /* Update DHCP state machine */ DHCP_state = DHCP_LINK_DOWN; #endif /* USE_DHCP */ /* When the netif link is down this function must be called.*/ netif_set_down(netif); #ifdef USE_LCD LCD_UsrLog ("The network cable is not connected \n"); #else BSP_LED_Off(LED1); BSP_LED_On(LED2); #endif /* USE_LCD */ } }
/** * @brief Initializes the lwIP stack * @param None * @retval None */ static void Netif_Config(void) { struct ip_addr ipaddr; struct ip_addr netmask; struct ip_addr gw; /* IP address setting */ 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_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(&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); } /* Set the link callback function, this function is called on change of link status*/ netif_set_link_callback(&gnetif, ethernetif_update_config); /* create a binary semaphore used for informing ethernetif of frame reception */ osSemaphoreDef(Netif_SEM); Netif_LinkSemaphore = osSemaphoreCreate(osSemaphore(Netif_SEM) , 1 ); link_arg.netif = &gnetif; link_arg.semaphore = Netif_LinkSemaphore; /* Create the Ethernet link handler thread */ #if defined(__GNUC__) osThreadDef(LinkThr, ethernetif_set_link, osPriorityNormal, 0, configMINIMAL_STACK_SIZE * 5); #else osThreadDef(LinkThr, ethernetif_set_link, osPriorityNormal, 0, configMINIMAL_STACK_SIZE * 2); #endif osThreadCreate (osThread(LinkThr), &link_arg); }
/** * @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; #ifndef USE_DHCP uint8_t iptab[4]; uint8_t iptxt[20]; #endif /* 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); #ifdef USE_LCD 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]); LCD_DisplayStringLine(Line8, (uint8_t*)" Static IP address "); LCD_DisplayStringLine(Line9, iptxt); #endif #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 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 */ } }
int main() { struct netif *netif, server_netif; struct ip_addr ipaddr, netmask, gw; /* the mac address of the board. this should be unique per board */ unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 }; netif = &server_netif; init_platform(); /* initliaze IP addresses to be used */ IP4_ADDR(&ipaddr, 192, 168, 1, 10); IP4_ADDR(&netmask, 255, 255, 255, 0); IP4_ADDR(&gw, 192, 168, 1, 1); print_app_header(); print_ip_settings(&ipaddr, &netmask, &gw); lwip_init(); /* Add network interface to the netif_list, and set it as default */ if (!xemac_add(netif, &ipaddr, &netmask, &gw, mac_ethernet_address, PLATFORM_EMAC_BASEADDR)) { xil_printf("Error adding N/W interface\n\r"); return -1; } netif_set_default(netif); /* Create a new DHCP client for this interface. * Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at * the predefined regular intervals after starting the client. */ /* dhcp_start(netif); */ /* now enable interrupts */ platform_enable_interrupts(); /* specify that the network if is up */ netif_set_up(netif); /* start the application (web server, rxtest, txtest, etc..) */ start_application(); /* receive and process packets */ while (1) { xemacif_input(netif); transfer_data(); } /* never reached */ cleanup_platform(); return 0; }
static void init_netifs(void) { #if PPP_SUPPORT pppInit(); #if PPP_PTY_TEST ppp_sio = sio_open(2); #else ppp_sio = sio_open(0); #endif if(!ppp_sio) { perror("Error opening device: "); exit(1); } #ifdef LWIP_PPP_CHAP_TEST pppSetAuth(PPPAUTHTYPE_CHAP, "lwip", "mysecret"); #endif pppOpen(ppp_sio, pppLinkStatusCallback, NULL); #endif /* PPP_SUPPORT */ #if LWIP_DHCP { IP4_ADDR(&gw, 0,0,0,0); IP4_ADDR(&ipaddr, 0,0,0,0); IP4_ADDR(&netmask, 0,0,0,0); netif_add(&netif, &ipaddr, &netmask, &gw, NULL, tapif_init, tcpip_input); netif_set_default(&netif); dhcp_start(&netif); } #else netif_set_default(netif_add(&netif,&ipaddr, &netmask, &gw, NULL, tapif_init, tcpip_input)); netif_set_up(&netif); #endif #if 0 /* Only used for testing purposes: */ netif_add(&ipaddr, &netmask, &gw, NULL, pcapif_init, tcpip_input); #endif #if LWIP_TCP //tcpecho_init(); //shell_init(); httpd_init(); #endif #if LWIP_UDP //udpecho_init(); #endif /* sys_timeout(5000, tcp_debug_timeout, NULL);*/ }
/* 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 ); }
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; }
/** * @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; #ifndef USE_DHCP uint8_t iptab[4]; uint8_t iptxt[20]; #endif /* Create tcp_ip stack thread */ tcpip_init( NULL, NULL ); /* IP address setting & display on STM32_evalboard LCD*/ #ifdef USE_DHCP ipaddr.addr = 0; netmask.addr = 0; gw.addr = 0; #else IP4_ADDR(&ipaddr, THIS_REMOTE_IP_ADDR0, THIS_REMOTE_IP_ADDR1, THIS_REMOTE_IP_ADDR2, THIS_REMOTE_IP_ADDR3); IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3); IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); #ifdef USE_LCD iptab[0] = THIS_REMOTE_IP_ADDR3; iptab[1] = THIS_REMOTE_IP_ADDR2; iptab[2] = THIS_REMOTE_IP_ADDR1; iptab[3] = THIS_REMOTE_IP_ADDR0; // sprintf((char*)iptxt, " %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]); //ShellPrintf("\r\n Static IP address = %d.%d.%d.%d\r\n", iptab[3], iptab[2], iptab[1], iptab[0]); // LCD_DisplayStringLine(Line8, (uint8_t*)" Static IP address "); // LCD_DisplayStringLine(Line9, iptxt); #endif #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(&xnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input); /* Registers the default network interface. */ netif_set_default(&xnetif); /* When the netif is fully configured this function must be called.*/ netif_set_up(&xnetif); }
static void lwip_set_link(struct vmm_netport *port) { struct lwip_netstack *lns = port->priv; if (port->flags & VMM_NETPORT_LINK_UP) { netif_set_up(&lns->nif); } else { netif_set_down(&lns->nif); } }
//Unshutdown a layer3 interface. BOOL lwipUnshutdownInterface(LPVOID pL3Interface) { struct netif* pif = (struct netif*)pL3Interface; if (NULL == pif) { BUG(); } netif_set_up(pif); return TRUE; }
/** * \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); } }
void initialize_network() { lwip_init(); netif_add(&interface, NULL, NULL, NULL, NULL, netif_init_cb, ip6_input); netif_create_ip6_linklocal_address(&interface, 1); interface.output_ip6 = ethip6_output; interface.linkoutput = eth_output; interface.input = ethernet_input; netif_set_up(&interface); netif_set_default(&interface); }
/** * @brief Initializes the lwIP stack * @param None * @retval None */ void lwip_sys_init(void) { struct ip_addr ipaddr; struct ip_addr netmask; struct ip_addr gw; uprintf_set_enable(UPRINT_INFO, UPRINT_BLK_NET, 1); uprintf_set_enable(UPRINT_DEBUG, UPRINT_BLK_NET, 0); /* Create tcp_ip stack thread */ tcpip_init( NULL, NULL ); /* IP address setting & display on STM32_evalboard LCD*/ #ifdef USE_DHCP ipaddr.addr = 0; netmask.addr = 0; gw.addr = 0; /* create a timer to start dhcp */ sys_timeout(2000, lwip_dhcp_start, &xnetif); #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); uprintf(UPRINT_INFO, UPRINT_BLK_NET, "LWIP eth0 IP: %d.%d.%d.%d\n", IP_ADDR0, IP_ADDR1, IP_ADDR2, 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(&xnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input); /* Registers the default network interface. */ netif_set_default(&xnetif); /* When the netif is fully configured this function must be called.*/ netif_set_up(&xnetif); /* attach ethernet isr */ bsp_isr_attach(16+ETH_IRQn, ethernetif_isr); bsp_irq_unmask(16+ETH_IRQn); }
void network_thread(void *p) { struct netif *netif; struct ip_addr ipaddr, netmask, gw; /* the mac address of the board. this should be unique per board */ unsigned char mac_ethernet_address[] = { 0x00, 0x0A, 0x35, 0x02, 0x2D, 0x8C }; netif = &server_netif; //xil_printf("Inside NW_THREAD\r\n"); #if 1 /* initliaze IP addresses to be used */ //IP4_ADDR(&ipaddr, 192, 168, 1, 10); //IP4_ADDR(&netmask, 255, 255, 255, 0); //IP4_ADDR(&gw, 192, 168, 1, 1); IP4_ADDR(&ipaddr, 10, 0, 18, 100); IP4_ADDR(&netmask, 255, 255, 255, 0); IP4_ADDR(&gw, 10, 0, 18, 1); #else IP4_ADDR(&ipaddr, 172, 16, 0, 10); IP4_ADDR(&netmask, 255, 255, 255, 0); IP4_ADDR(&gw, 172, 16, 0, 1); #endif /* print out IP settings of the board */ print("\r\n\r\n"); print("-----BPM Server Application ------\r\n\n"); print_ip_settings(&ipaddr, &netmask, &gw); /* print all application headers */ print_headers(); /* Add network interface to the netif_list, and set it as default */ if (!xemac_add(netif, &ipaddr, &netmask, &gw, mac_ethernet_address, PLATFORM_EMAC_BASEADDR)) { xil_printf("Error adding N/W interface\r\n"); return; } netif_set_default(netif); /* specify that the network if is up */ netif_set_up(netif); /* start packet receive thread - required for lwIP operation */ sys_thread_new("xemacif_input_thread", (void(*)(void*))xemacif_input_thread, netif, THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); /* now we can start application threads */ launch_app_threads(); return; }
/** * eth_netif_init * * @param none * @return none * * @brief init eth netif */ void eth_netif_init(IPConfigStruct ipConfig) { ip_addr_t eth_ipaddr, eth_netmask, eth_gw; IP4_ADDR(ð_gw,ipConfig.gw[0],ipConfig.gw[1],ipConfig.gw[2],ipConfig.gw[3]); IP4_ADDR(ð_ipaddr, ipConfig.ip[0],ipConfig.ip[1],ipConfig.ip[2],ipConfig.ip[3]); IP4_ADDR(ð_netmask,ipConfig.sub[0],ipConfig.sub[1],ipConfig.sub[2],ipConfig.sub[3]); netif_add(ð_netif, ð_ipaddr, ð_netmask, ð_gw, NULL, ethernetif_init, tcpip_input); netif_set_up(ð_netif); }
static void default_netif_add(void) { IP4_ADDR(&test_gw, 192,168,0,1); IP4_ADDR(&test_ipaddr, 192,168,0,1); IP4_ADDR(&test_netmask, 255,255,0,0); fail_unless(netif_default == NULL); netif_set_default(netif_add(&test_netif, &test_ipaddr, &test_netmask, &test_gw, NULL, default_netif_init, NULL)); netif_set_up(&test_netif); }
void my_lwip_init(void) { struct ip_addr ipaddr, netmask, gw; u8_t bTemp; tcpip_init(NULL, NULL); IP4_ADDR(&gw, 192,168,1,1); IP4_ADDR(&ipaddr, 192,168,1,2); IP4_ADDR(&netmask, 255,255,255,0); netif_add(&net_if, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input); netif_set_default(&net_if); netif_set_up(&net_if); }
/** * \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 }
static void test_ip6_ll_addr_iter(int expected_ctr1, int expected_ctr2) { fail_unless(linkoutput_ctr == 0); /* test that nothing is sent with link uo but netif down */ netif_set_link_up(&test_netif6); ip6_test_handle_timers(500); fail_unless(linkoutput_ctr == 0); netif_set_link_down(&test_netif6); fail_unless(linkoutput_ctr == 0); /* test that nothing is sent with link down but netif up */ netif_set_up(&test_netif6); ip6_test_handle_timers(500); fail_unless(linkoutput_ctr == 0); netif_set_down(&test_netif6); fail_unless(linkoutput_ctr == 0); /* test what is sent with link up + netif up */ netif_set_link_up(&test_netif6); netif_set_up(&test_netif6); ip6_test_handle_timers(500); fail_unless(linkoutput_ctr == expected_ctr1); netif_set_down(&test_netif6); netif_set_link_down(&test_netif6); fail_unless(linkoutput_ctr == expected_ctr1); linkoutput_ctr = 0; netif_set_up(&test_netif6); netif_set_link_up(&test_netif6); ip6_test_handle_timers(500); fail_unless(linkoutput_ctr == expected_ctr2); netif_set_link_down(&test_netif6); netif_set_down(&test_netif6); fail_unless(linkoutput_ctr == expected_ctr2); linkoutput_ctr = 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, ð_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 }/*}}}*/
void SetLwIP(void) { extern err_t ethernetif_init( struct netif *netif ); struct ip_addr xIpAddr, xNetMast, xGateway; /* 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); }
int ethernet_interface_connect(unsigned int timeout_ms) { NVIC_SetPriority(ENET_IRQn, ((0x01 << 3) | 0x01)); NVIC_EnableIRQ(ENET_IRQn); if (use_dhcp) { dhcp_start(&lpcNetif); } else { netif_set_up(&lpcNetif); } // -1: error, 0: timeout int inited = wait_mySemaphore(&netif_inited, timeout_ms); return (inited > 0) ? (0) : (-1); }
/*! * \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 }
int STM32F4_ETH_LWIP_Driver::Open(int index) { /* Network interface variables */ struct ip_addr ipaddr, subnetmask, gateway; struct netif *pNetIF; int len; const SOCK_NetworkConfiguration *iface; EthernetPrepareZero(); /* Enable Phy Powerdown on Deepsleep */ STM32F4_SetPowerHandlers(EthernetDeepSleep, EthernetWakeUp); /* Apply network configuration */ iface = &g_NetworkConfig.NetworkInterfaces[index]; len = g_STM32F4_ETH_NetIF.hwaddr_len; if (len == 0 || iface->macAddressLen < len) { len = iface->macAddressLen; g_STM32F4_ETH_NetIF.hwaddr_len = len; } memcpy(g_STM32F4_ETH_NetIF.hwaddr, iface->macAddressBuffer, len); ipaddr.addr = iface->ipaddr; gateway.addr = iface->gateway; subnetmask.addr = iface->subnetmask; pNetIF = netif_add( &g_STM32F4_ETH_NetIF, &ipaddr, &subnetmask, &gateway, NULL, STM32F4_ETH_ethhw_init, ethernet_input ); CPU_INTC_ActivateInterrupt(ETH_IRQn, (HAL_CALLBACK_FPN)STM32F4_ETH_LWIP_interrupt, &g_STM32F4_ETH_NetIF); netif_set_default( pNetIF ); if (LwipNetworkStatus) { netif_set_up( pNetIF ); } else { netif_set_down( pNetIF); } /* Initialize the continuation routine for the driver interrupt and receive */ InitContinuations( pNetIF ); /* Return LWIP's net interface number */ return g_STM32F4_ETH_NetIF.num; }
void lwip_init_task(void) { struct ip_addr ipaddr, netmask, gw; tcpip_init(NULL, NULL); lpc17xx_netif = mem_malloc(sizeof(struct netif)); IP4_ADDR(&gw, 192,168,223,2); IP4_ADDR(&ipaddr, 192,168,223,17); IP4_ADDR(&netmask, 255,255,255,128); netif_set_default(netif_add(lpc17xx_netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input)); netif_set_up(lpc17xx_netif); }
static void tcpip_init_done(void *arg) { ip_addr_t ipaddr, netmask, gateway; sys_sem_t *sem; sem = arg; dpdkif_get_if_params(&ipaddr, &netmask, &gateway, netif.hwaddr); netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gateway, NULL, dpdkif_init, tcpip_input)); netif_set_up(&netif); sys_sem_signal(sem); }
static void lwip_init(void) { struct ip_addr ipaddr, netmask, gw; extern err_t ethernetif_init( struct netif *netif ); tcpip_init(NULL, NULL); macnet_netif = mem_malloc(sizeof(struct netif)); IP4_ADDR(&gw, 192,168,1,1); IP4_ADDR(&ipaddr, 192,168,1,100); IP4_ADDR(&netmask, 255,255,255,0); netif_set_default(netif_add(macnet_netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input)); netif_set_up(macnet_netif); }
/** * @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 #ifdef USER_DEFINE_NET IP4_ADDR(&ipaddr, ip_address[0], ip_address[1], ip_address[2], ip_address[3]); IP4_ADDR(&netmask, mask_address[0], mask_address[1] , mask_address[2], mask_address[3]); IP4_ADDR(&gw, gate_address[0], gate_address[1], gate_address[2], gate_address[3]); #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); #endif #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); }
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); }