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: DHCP - Ip.autoIp = true;

MCU: TM4C1294NCPDT

TI-RTOS: v2.01.00.03

NDK: v2.23.01.01

CCS: v6.0.1.0040

-

Hello,

    How do we change the property Ip.autoIp from true to false or vice versa during run-time? All I mean to say is that, I want to change between DHCP enabled & disabled during run-time (in code & not in .cfg file).

-

Thanks

-

Regards

Soumyajit

  • Hi Soumyajit,

    You can do this at run time.  You must use the NDK's C runtime configuration APIs (discussed in detail in the NDK API guide, Appendix G "Legacy Configuration Manager API"), such as CfgAddEntry, etc.

    You can use a "cheat" to get this code from your application.  First, build your app with DHCP client configured.  Then look at the generated C file (e.g. in your project's sub folder Debug\configPkg\package\cfg\<project name>_pem4f.c).  Then in the function "ti_ndk_config_ip_init" you can find the C code to configure your app to be a DHCP client.

    Change the configuration for a static IP, rebuild.  Again, look at the ti_ndk_config_ip_init function and this time you will see the settings for a static IP.

    Please also refer to this related thread which has more info on this.

    Steve

  • Hi Steven,
    Thanks for the reply. I have earlier successfully implemented IP address changing during run time & it worked. But am unable to figure out how the DHCP can be enabled or disabled!! I have gone through the NDK API Guide also but it seems not that helpful in this matter.
    I am providing below the function that is currently in my code (being triggered by the Network Open Hook) related to changing the IP address. Would you mind adding a few lines of code to it showing the DHCP enabling & disabling? Thanks for your help.
    -
    Void functionNetworkOpenHook(Void)
    {
    CI_IPNET NA;

    HANDLE hCfgIpAddr;

    /* Setup manual IP address */
    bzero(&NA, sizeof(NA));
    NA.IPAddr = inet_addr("192.168.1.2");
    NA.IPMask = inet_addr("255.255.255.0");
    strcpy(NA.Domain, "demo.net");
    NA.NetType = 0;

    /* get the current static IP entry */
    CfgGetEntry(0, CFGTAG_IPNET, 1, 1, &hCfgIpAddr);

    /* remove the current static IP entry */
    CfgRemoveEntry(0, hCfgIpAddr);

    /* add a new static IP entry */
    CfgAddEntry(0, CFGTAG_IPNET, 1, 0,
    sizeof(CI_IPNET), (UINT8 *)&NA, 0);
    }
    -
    Thanks
    -
    Regards
    Soumyajit
  • Also,
    Will the following code help in setting the configuration of the NDK to DHCP client (enabled) if the function is executed. If so, how to disable the DHCP client & work on static IP.
    -
    dhcp_client_example()
    {
    CI_SERVICE_DHCPC dhcpc;
    bzero( &dhcpc, sizeof(dhcpc) );
    dhcpc.cisargs.Mode = CIS_FLG_IFIDXVALID;
    dhcpc.cisargs.IfIdx = dhcpIdx;
    dhcpc.cisargs.pCbSrv = &ServiceReport;
    CfgAddEntry( hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT, 0,
    sizeof(dhcpc), (UINT8 *)&dhcpc, 0 );
    }
    -
    Thanks
    -
    Regards
    Soumyajit

  • Hi Soumyajit,

    Can you try using the CfgGetEntry() and CfgRemoveEntry() APIs for CFGITEM_SERVICE_DCHPCLIENT, similar to how you did for the static IP address removal?

    Steve

  • 0724.NDK_good_example_client.c

    Hi Steven,

     Thanks for putting in your valuable time for my queries. I found out this code file on google & I think it clearly indicates the enabling & disabling of DCHP. Will try out the code parts very soon!!

    -

    Thanks

    -

    Regards

    Soumyajit