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.

NDK Restarting DHCP client

Hi, 

we are using NDK v2.23.2.03.

the NDK is configured using the XCONF tool

we want to be able to restart the DHCP client because we either switched networks or just lost the link on the same network and want to be sure we get the same IP address.  

i saw in the documentation the DHCPOpen/close routines but there is very little on how to configure them.  when i try to configure it like so:

NTARGS args;
NTPARAM_DHCP dhcpParams;

if(hDHCPCfg != NULL)
{
DHCPClose(hDHCPCfg);
}

memset(&args, NULL, sizeof(args));
memset(&dhcpParams, NULL, sizeof(dhcpParams));

args.CallMode = NT_MODE_IFIDX;
//args.IPAddr = ;
args.IfIdx = 1;
args.hCallback = hDHCPCfg;
args.pCb = &NDKServiceReport;


hDHCPCfg = DHCPOpen(&args, &dhcpParams);

i get errors in the log:

Service Status: DHCPC : Enabled : Running : 000
Network Added: If-1:192.168.1.9
Service Status: DHCPC : Enabled : Running : 017
00024.500 Illegal reentrant call to llEnter()
00024.500 Illegal call to llExit()
Network Removed: If-1:192.168.1.9

i know i must have it configured wrong or i am somehow supposed to shut down the existing DHCP service.  i hoping there is just some command i can send to the existing DHCP service to just restart it instead of starting a brand new one.

so i need to know either:

1) what is the correct way to restart the existing DHCP client so i can get a new IP address

or

2) what is the correct way to shut down, configure, and start a new DHCP service?

  • Here's example code that shows enabling and disabling DHCP.  The function can be made into a Task to test it.

    I added a sleep to ensure that the IP address is obtained by the DHCP server.  The code will first get the default configuration, then remove DHCP client from the configuration, and finally re-add it.

     

    #include <ti/sysbios/BIOS.h>
    
    #include <ti/sysbios/knl/Task.h>
    
     
    
    #include <netmain.h>
    
    #include <stkmain.h>
    
     
    
    extern void ti_ndk_config_Global_serviceReport();
    
     
    
    void restartDhcp()
    
    {
    
        HANDLE hCfg = 0;
    
        HANDLE entry;
    
        int status;
    
     
    
        Task_sleep(5000);
    
        System_printf("ipaddrhook: IP addr added, now remove it:\n");
    
     
    
        /* get the default configuration */
    
        hCfg = CfgGetDefault();
    
        if (!hCfg) {
    
            System_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) {
    
            System_printf("ipaddrhook: error, couldn't get DHCP client entry\n");
    
        }
    
     
    
        /* remove the DHCP client configuration */
    
        status = CfgRemoveEntry(hCfg, entry);
    
        if (status < 0) {
    
            System_printf("ipaddrhook: error, couldn't remove DHCP client entry (%d)\n", status);
    
        }
    
     
    
        /* now, add it back */
    
        {
    
            CI_SERVICE_DHCPC dhcpc;
    
            UINT8 DHCP_OPTIONS[] =
    
                    {
    
                    DHCPOPT_SUBNET_MASK,
    
                    };
    
                                                       
    
            /* Specify DHCP Service on IF specified by "IfIdx" */
    
            bzero(&dhcpc, 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;
    
            CfgAddEntry(hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT, 0,
    
                    sizeof(dhcpc), (UINT8 *)&dhcpc, 0);
    
        }
    
     
    
    }
    
     

    Then, DHCP is disabled by the above code.  Lastly, it is again enabled and then you see the IP address again added back.

    Looking at the output below, you can see the configuration for DHCP client is enabled, and then the IP address is obtained as normal from the DHCP server.

     

    Using MAC address in flash

    Starting the TCP Echo example

    System provider is set to SysMin. Halt the target to view any SysMin contents in ROV.

    Service Status: DHCPC    : Enabled  :          : 000

    Service Status: DHCPC    : Enabled  : Running  : 000

    Network Added: If-1:146.252.163.85

    Service Status: DHCPC    : Enabled  : Running  : 017

    ipaddrhook: IP addr added, now remove it:

    Network Removed: If-1:146.252.163.85

    Service Status: DHCPC    : Disabled :          : 000

    Service Status: DHCPC    : Enabled  : Running  : 000

    Service Status: DHCPC    : Enabled  : Running  : 000

    Network Added: If-1:146.252.163.85

    Service Status: DHCPC    : Enabled  : Running  : 017

    Let me know if this helps.

    Regards,

    Moses

  • lately to get around this we have been issuing NC_NetSTop(1); and that seems to be doing what we need right now.

    is this safer than issuing a netstop? What are the advantages to doing this over issuing a netstop?
  • Calling NC_NetStop(1) reboots the entire network stack while the example I gave only removes DHCP and re-adds it.

    Moses
  • so when i run this code i get errors and this on my console

    [C674X_0] Service Status: DHCPC : Enabled : : 000
    Service Status: DHCPC : Enabled : Running : 000
    Network Added: If-1:192.168.1.9
    Service Status: DHCPC : Enabled : Running : 017
    00064.800 Illegal reentrant call to llEnter()
    Network Removed: If-1:192.168.1.9
    Service Status: DHCPC : Disabled : : 000
    Service Status: DHCPC : Enabled : : 000
    00065.100 Illegal call to llExit()
    Service Status: DHCPC : Disabled : : 000
    00065.303 mmFree: Double Free

  • The code sample I sent you earlier was tested on a TivaC device. I just ported it to EVM6748 and still not seeing this issue. I'm attaching my project here. Also I'm using NDK 2.24.03.35 and BIOS 6_42_01_16_eng

    7827.rebootDhcp.zip

    Run this and let me know if it works for you

    Let me know if this helps

    Moses

  • Thank you for you code, it works well according to my test.