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.

AM4376: Unable to Restart DHCP client in run time

Part Number: AM4376
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/439972/ndk-restarting-dhcp-client

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/406303/dhcp-client

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/505226/handling-dhcp-client-timeout

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.

  • Hi, 

    Apologies for the delay in responding. I need to assign to another team member with the SW you are requesting support on. 

    Best Regards,

    Schuyler

  • Hi Schuyler,

    Thanks for the response,

    Will be expecting the solution regarding the same since it is one of the requirement in our existing development. Also one observation regarding the above mentioned links,

    There are some source codes shared in the above links but when I try to download the same then it says you do not have the permissions to download. It is expected that we should be able to download the source code shared in the forums.

    BR, 

    Gaurav More

  • Hi Schuyler,

    One more input I missed. I am able to restart the DHCP client using netStart function. But not able to switch between DHCP and Static IP.

    Below is the code snippet regarding the same which I referred from the one of the above link,

    void dhcpToStatic()
    {
        CI_IPNET NA;
        CI_ROUTE RT;
    
        HANDLE hCfgIpAddr;
        int status = 0;
    
        bzero(&NA, sizeof(NA));
        NA.IPAddr = inet_addr(ipAddr);
        NA.IPMask = inet_addr(ipMask);
        strcpy(NA.Domain, IpDomainName);
        NA.NetType = 4;
    
        status =  CfgGetEntry(0, CFGTAG_IPNET, 1, 1, &hCfgIpAddr);
        UART_printf("CfgGetEntry %d\n", status);
    
        status = CfgRemoveEntry(0, hCfgIpAddr);
        UART_printf("CfgRemoveEntry %d\n", status);
    
    
        status = CfgAddEntry(0, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET), (uint8_t*)&NA, NULL);
        UART_printf("CfgAddEntry %d\n", status);
    
        bzero(&RT, sizeof(RT));
        RT.IPDestAddr = 0;
        RT.IPDestMask = 0;
        RT.IPGateAddr = inet_addr(ipGateway);
    
        status =  CfgGetEntry(0, CFGTAG_ROUTE, 0, 0, &hCfgIpAddr);
            UART_printf("CfgGetEntry RT:  %d\n", status);
    
        status = CfgRemoveEntry(0, hCfgIpAddr);
        UART_printf("CfgRemoveEntry RT: %d\n", status);
    
        status = CfgAddEntry(0, CFGTAG_ROUTE, 0, 0, sizeof(CI_ROUTE), (uint8_t *)&RT, 0);
    
        UART_printf("CfgAddEntry  RT: %d\n", status);
    
    }
    

    After calling this it is showing the error in case of 

       bzero(&RT, sizeof(RT));
        RT.IPDestAddr = 0;
        RT.IPDestMask = 0;
        RT.IPGateAddr = inet_addr(ipGateway);
    
        status =  CfgGetEntry(0, CFGTAG_ROUTE, 0, 0, &hCfgIpAddr);
            UART_printf("CfgGetEntry RT:  %d\n", status);
    
        status = CfgRemoveEntry(0, hCfgIpAddr);
        UART_printf("CfgRemoveEntry RT: %d\n", status);
    
        status = CfgAddEntry(0, CFGTAG_ROUTE, 0, 0, sizeof(CI_ROUTE), (uint8_t *)&RT, 0);
    
        UART_printf("CfgAddEntry  RT: %d\n", status);

    the output I see on the screen is

     CfgAddEntry  RT: -101

    BR,

    Gaurav More

  • Hi Gaurav,

    When I investigated finding support for your question I found that TI no longer supports the NDK or Sysbios on the AM437. Here is a link though to possible options.

    Best Regards,

    Schuyler