Other Parts Discussed in Thread: SYSBIOS
Hi,
I am trying to implement the application where initially the DHCP client is enabled in .confg file and accordingly it also gets the IP address from the DHCP server. But when I remove the Ethernet cable and again reconnect it then it is not updating the new IP address using DHCP client.
I referred below mentioned links for the same and implemented the way it has been suggested.
https://e2e.ti.com/support/processors-group/processors/f/processors-forum/406303/dhcp-client
But after implementing it I verified the same but it is not working. below is the code snippet for DHCP restart
void DHCP_restart(void) { HANDLE hCfg = 0; HANDLE entry; int status; /* get the default configuration */ hCfg = CfgGetDefault(); if (!hCfg) { UART_printf("ipaddrhook: error, couldn't get default config\n"); } /* get the DHCP client configuration */ status = CfgGetEntry(hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT, 1, &entry); if (!status) { UART_printf("ipaddrhook: error, couldn't get DHCP client entry\n"); } /* remove the DHCP client configuration */ status = CfgRemoveEntry(hCfg, entry); if (status < 0) { UART_printf("ipaddrhook: error, couldn't remove DHCP client entry (%d)\n", status); } UART_printf("DHCP removed\n"); dhcpOptionsClear(); /* Use DHCP to obtain IP address on interface 1 */ { CI_SERVICE_DHCPC dhcpc; static unsigned char DHCP_OPTIONS[] = { DHCPOPT_SUBNET_MASK, }; /* Specify DHCP Service on IF specified by "IfIdx" */ memset(&dhcpc, 0, sizeof(dhcpc)); dhcpc.cisargs.Mode = 1; dhcpc.cisargs.IfIdx = 1; dhcpc.cisargs.pCbSrv = &ti_ndk_config_Global_serviceReport; dhcpc.param.pOptions = DHCP_OPTIONS; dhcpc.param.len = 1; int ret = CfgAddEntry(hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT, 0, sizeof(dhcpc), (unsigned char *)&dhcpc, 0); UART_printf("RET %d\n", ret); // System_flush(); } }
While executing this I observed that the code is not able to initiate the query. it sends the StateSelecting query but then after maximum tries it goes to
/* Failed to get proper response */
pLease->StateNext = INIT;
TaskSleep( 5*1000 ); /* wait 5 seconds before trying again */
return;
inside the StateSelecting (). But then when i checked for DHCP state function it is not coming to
case INIT :
dhcpSocketClose( pLease );
goto restartLoop;
which is expected. let me know if I am missing any method of restarting the DHCP client in the run time.
Also one more query regarding the dhcpIPRemove (). How to use this function apart from the inbuild code since it has the below mentioned line in the function
/* Notify system of new state */
if( pLease->pCb )
(*pLease->pCb)( pLease->hCb, NETTOOLS_STAT_RUNNING+DHCPCODE_IPREMOVE );
Which I doubt will intiaited the proper DHCP restart execution.
Please revert with the suggestion since it is required for our application.
BR,
Gaurav More.