//***************************************************************************** // //! Change the configuration of the lwIP network interface. //! //! \param ulIPAddr is the new IP address to be used (static). //! \param ulNetMask is the new network mask to be used (static). //! \param ulGWAddr is the new Gateway address to be used (static). //! \param ulIPMode is the IP Address Mode. \b IPADDR_USE_STATIC 0 will force //! static IP addressing to be used, \b IPADDR_USE_DHCP will force DHCP with //! fallback to Link Local (Auto IP), while \b IPADDR_USE_AUTOIP will force //! Link Local only. //! //! This function will evaluate the new configuration data. If necessary, the //! interface will be brought down, reconfigured, and then brought back up //! with the new configuration. //! //! \return None. // //***************************************************************************** void lwIPNetworkConfigChange(struct netif *netif, IP_CONFIG * ipCfg) { struct ip_addr ip_addr; struct ip_addr net_mask; struct ip_addr gw_addr; IP_CONFIG currentIPConfig; // Check the parameters. #if LWIP_DHCP && LWIP_AUTOIP ASSERT((ipCfg->IPMode == IPADDR_USE_STATIC) || (ipCfg->IPMode == IPADDR_USE_DHCP) || (ipCfg->IPMode == IPADDR_USE_AUTOIP)) #elif LWIP_DHCP ASSERT((ipCfg->IPMode == IPADDR_USE_STATIC) || (ipCfg->IPMode == IPADDR_USE_DHCP)) #elif LWIP_AUTOIP ASSERT((ipCfg->IPMode == IPADDR_USE_STATIC) || (ipCfg->IPMode == IPADDR_USE_AUTOIP)) #else ASSERT(ipCfg->IPMode == IPADDR_USE_STATIC) #endif // Setup the network address values. if (ipCfg->IPMode == IPADDR_USE_STATIC) { ip_addr.addr = htonl(ipCfg->IPAddr); net_mask.addr = htonl(ipCfg->NetMask); gw_addr.addr = htonl(ipCfg->GWAddr); } #if LWIP_DHCP || LWIP_AUTOIP else { ip_addr.addr = 0; net_mask.addr = 0; gw_addr.addr = 0; } #endif // Switch on the current IP Address Aquisition mode. currentIPConfig.IPMode = IPADDR_USE_DHCP; LWIPServiceTaskIPConfigGet(netif, ¤tIPConfig); switch (currentIPConfig.IPMode) { // Static IP case IPADDR_USE_STATIC: { // Set the new address parameters. This will change the address // configuration in lwIP, and if necessary, will reset any links // that are active. This is valid for all three modes. // netif_set_addr(netif, &ip_addr, &net_mask, &gw_addr); // If we are going to DHCP mode, then start the DHCP server now. #if LWIP_DHCP if (ipCfg->IPMode == IPADDR_USE_DHCP) { dhcp_start(netif); } #endif // If we are going to AutoIP mode, then start the AutoIP process // now. #if LWIP_AUTOIP if (ipCfg->IPMode == IPADDR_USE_AUTOIP) { autoip_start(netif); } #endif // And we're done. break; } // DHCP (with AutoIP fallback). #if LWIP_DHCP case IPADDR_USE_DHCP: { // // If we are going to static IP addressing, then disable DHCP and // force the new static IP address. // if (ipCfg->IPMode == IPADDR_USE_STATIC) { dhcp_stop(netif); // SEE bug http://savannah.nongnu.org/bugs/?22804 netif->flags &= ~NETIF_FLAG_DHCP; netif_set_addr(netif, &ip_addr, &net_mask, &gw_addr); } // If we are going to AUTO IP addressing, then disable DHCP, set // the default addresses, and start AutoIP. #if LWIP_AUTOIP else if (ipCfg->IPMode == IPADDR_USE_AUTOIP) { dhcp_stop(netif); netif_set_addr(netif, &ip_addr, &net_mask, &gw_addr); autoip_start(netif); } #endif break; } #endif // AUTOIP #if LWIP_AUTOIP case IPADDR_USE_AUTOIP: { // // If we are going to static IP addressing, then disable AutoIP and // force the new static IP address. // if (ulIPMode == IPADDR_USE_STATIC) { autoip_stop(netif); netif_set_addr(netif, &ip_addr, &net_mask, &gw_addr); } // // If we are going to DHCP addressing, then disable AutoIP, set the // default addresses, and start dhcp. // #if LWIP_DHCP else if (ulIPMode == IPADDR_USE_AUTOIP) { autoip_stop(netif); netif_set_addr(netif, &ip_addr, &net_mask, &gw_addr); dhcp_start(netif); } #endif break; } #endif } }
void ethernetThread(void *pParams) { IP_CONFIG ipconfig; unsigned char hwaddr[6] = {0, 0, 0, 0, 0, 0}; char s[64]; /* sprintf string */ ETHServiceTaskInit(0); ETHServiceTaskFlush(0,ETH_FLUSH_RX | ETH_FLUSH_TX); /* * Allow make SET_IP_ADR="-D SET_IP_ADR=\"(192<<24|168<<16|98<<8|29)\"" * to build application with a recovery IP address. */ #ifndef SET_IP_ADR #define SET_IP_ADR 0 #endif if (SET_IP_ADR) { ipconfig.IPMode = IPADDR_USE_STATIC; ipconfig.IPAddr = SET_IP_ADR; #ifndef SET_NET_MASK #define SET_NET_MASK 0xffffff00 #endif ipconfig.NetMask = SET_NET_MASK; #ifndef SET_GW_ADR #define SET_GW_ADR (((SET_IP_ADR)&(SET_NET_MASK))|0x00000001) #endif ipconfig.GWAddr = SET_GW_ADR; } else { ipconfig.IPMode = usercfg.IPMode; ipconfig.IPAddr = IP2LONG(usercfg.ip[0], usercfg.ip[1], usercfg.ip[2], usercfg.ip[3]); ipconfig.NetMask = IP2LONG(usercfg.netmask[0], usercfg.netmask[1], usercfg.netmask[2], usercfg.netmask[3]); ipconfig.GWAddr= IP2LONG(usercfg.gateway[0], usercfg.gateway[1], usercfg.gateway[2], usercfg.gateway[3]); } LWIPServiceTaskInit(&ipconfig); /* * Get actual MAC and IP address programmed */ EthernetMACAddrGet(ETH_BASE, &hwaddr[0]); LWIPServiceTaskIPConfigGet(&lwip_netif, &ipconfig); /* * Print Ethernet configuration to serial */ lprintf("\r\n"); lprintf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]); lprintf(" IP: %d.%d.%d.%d\r\n", ipconfig.IPAddr>>0 & 0xff, ipconfig.IPAddr>>8 & 0xff, ipconfig.IPAddr>>16 & 0xff, ipconfig.IPAddr>>24 & 0xff ); lprintf("\r\n"); #if (PART == LM3S8962) /* * Print Ethernet configuration to OLED screen */ sprintf(s, "MAC %02X:%02X:%02X:%02X:%02X:%02X", hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]); RIT128x96x4StringDraw(s, 0, RITLINE(5), 15); sprintf(s, "IP %d.%d.%d.%d", ipconfig.IPAddr>>0 & 0xff, ipconfig.IPAddr>>8 & 0xff, ipconfig.IPAddr>>16 & 0xff, ipconfig.IPAddr>>24 & 0xff ); RIT128x96x4StringDraw(s, 0, RITLINE(6), 15); #endif syslogInit(); syslog(facility_local0 , level_err, "A message from QuickStart" ); /* Nothing else to do. No point hanging around. */ vTaskDelete( NULL); /* We should not get here. */ return; }