This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi, I faced with some problem in LwIP. I make an application with user interface with possibility to switch between static IP and DHCP. But DHCP isn't properly initialize and lwIPInit() doesn't return IP address (it returns zeroes as defaults during initialization). In some times It works correct and I receive IP from DHCP, but this case is happens absolutely randomly. Static IP initialized correctly at any request. Do you have any idea about this issue? Here is my code from lwIPInit()
/* This is a peace of code from where I make a choise between static IP and DHCP*/ case MODULES_NETWORK_IP_STATIC: /* IPaddr NetMask Gate */ //uint32_t htonl_aaddr = lwip_htonl(&network.sv_ip_addr); ipAddr = lwIPInit(0, macAddress, network.sv_ip_addr, network.sv_ip_mask, network.sv_ip_gate, IPADDR_USE_STATIC, lwip_init_seq); break; case MODULES_NETWORK_IP_DHCP: /* Initialze the lwIP library, using DHCP.*/ ipAddr = lwIPInit(0, macAddress, 0, 0, 0, IPADDR_USE_DHCP, lwip_init_seq); break; ////////////////////////////////////////////////////////////////////////////////////////// extern main_database_t main_database; unsigned int lwIPInit(unsigned int instNum, unsigned char *macArray, unsigned int ipAddr, unsigned int netMask, unsigned int gwAddr, unsigned int ipMode, unsigned int inited) { struct ip_addr ip_addr; struct ip_addr net_mask; struct ip_addr gw_addr; volatile unsigned char *state; unsigned int *ipAddrPtr; volatile unsigned int cnt = 0x3FFFFFFF; lwip_init(); /* Setup the network address values. */ if(ipMode == IPADDR_USE_STATIC) { ip_addr.addr = htonl(ipAddr); net_mask.addr = htonl(netMask); gw_addr.addr = htonl(gwAddr); } else { ip_addr.addr = 0; net_mask.addr = 0; gw_addr.addr = 0; } hdkif_macaddrset(instNum, macArray); /* ** Create, configure and add the Ethernet controller interface with ** default settings. ip_input should be used to send packets directly to ** the stack. The lwIP will internaly call the hdkif_init function. */ if(inited){ if(NULL == netif_add(&hdkNetIF[instNum], &ip_addr, &net_mask, &gw_addr, &instNum, hdkif_init, ip_input)) { return 0; }; }else{ dhcp_stop(&hdkNetIF[instNum]); netif_set_down(&hdkNetIF[instNum]); netif_set_addr(&hdkNetIF[instNum], &ip_addr, &net_mask, &gw_addr); } netif_set_default(&hdkNetIF[instNum]); /* Start DHCP, if enabled. */ #if LWIP_DHCP if(ipMode == IPADDR_USE_DHCP) { dhcp_start(&hdkNetIF[instNum]); } #endif /* Start AutoIP, if enabled and DHCP is not. */ #if LWIP_AUTOIP if(ipMode == IPADDR_USE_AUTOIP) { autoip_start(&hdkNetIF[instNum]); } #endif if(ipMode != IPADDR_USE_STATIC) { /* wait till the dynamic IP address is properly assigned */ state = &(hdkNetIF[instNum].dhcp->state); cnt = 20; while(*state != DHCP_BOUND){ vTaskDelay(1000); cnt--; if(cnt == 0) return 0; } } else { /* Bring the interface up */ netif_set_up(&hdkNetIF[instNum]); } ipAddrPtr = (unsigned int*)&(hdkNetIF[instNum].ip_addr); main_database.sv_ip_addr = *(unsigned int*)&(hdkNetIF[instNum].ip_addr); main_database.sv_ip_mask = *(unsigned int*)&(hdkNetIF[instNum].netmask); main_database.sv_ip_gate = *(unsigned int*)&(hdkNetIF[instNum].gw); return (*ipAddrPtr); }
Hi Oleksii,
I started to work on your issue and i will get back to you with an update soon.
--
Thanks & Regards,
Jagadish.
Hi Oleksii,
Can you make sure "DHCP_DOES_ARP_CHECK" set to 1. If it is set to 0 then please make it to 1 and test it.
--
Thanks,
Jagadish.
Hi, thanks for your advice. I set 1 into DHCP_DOES_ARP_CHECK macro, but it doesn't help. All attempts to request IP from DHCP takes more than 2 minutes. Sometimes process of IP address requesting stucks system until reboot.
May be the problem is here. I use one interface for DHCP and static, and also when I change IP setting I always use dhcp_stop(), may it cause some problems? The state machine description is next: when the system is booting, I call netif_add() to create instance, this function calls only once during initialization, after that at every attempt to get new IP calls else statement.
if(inited){ if(NULL == netif_add(&hdkNetIF[instNum], &ip_addr, &net_mask, &gw_addr, &instNum, hdkif_init, ip_input)) { return 0; }; }else{ dhcp_stop(&hdkNetIF[instNum]); netif_set_down(&hdkNetIF[instNum]); netif_set_addr(&hdkNetIF[instNum], &ip_addr, &net_mask, &gw_addr); } netif_set_default(&hdkNetIF[instNum]);
I stuck in this loop, because state isn't set into DHCP_BOUND
while(*state != DHCP_BOUND){ vTaskDelay(1000); cnt--; if(cnt == 0) return 0; }
Hi Oleksii,
Can you please share your entire project for my debugging purpose?
--
Thanks & Regards,
Jagadish.
Hi,
Closing the thread because of not hearing back from so long.
--
Thanks & regards,
Jagadish.