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.

Getting IP, Subnet Mask, Gateway IP & DNS IP while DHCP is enabled

MCU: TM4C1294NCPDT

TI-RTOS: v2.01.00.03

NDK: v2.23.01.01

CCS: v6.0.1.0040

-

Hi,

Currently, I am using the below mentioned function to detect the self IP while using LAN/Ethernet in DHCP enabled mode. Can you please tell me which function or API to use to get the other parameters like Subnet Mask, Gateway IP & DNS IP (while DHCP is enabled). In a windows OS PC, if we type "ipconfig /all" at the command prompt we get all details (Current IP, Subnet Mask, Gateway IP, DNS IP) even if the PC's LAN is in DHCP enabled mode; similarly I need to know what configuration(s) the NDK have received from the network during DHCP.

-

void mynetworkIPAddrHook(IPN IPAddr, uint IfIdx, uint fAdd)
{
IPN IPTmp;

IPTmp = ntohl(IPAddr);

System_printf("networkIPAddrHook:\tIf-%d:%d.%d.%d.%d\n", IfIdx,
(UINT8)(IPTmp>>24)&0xFF, (UINT8)(IPTmp>>16)&0xFF,
(UINT8)(IPTmp>>8)&0xFF, (UINT8)IPTmp&0xFF);

sprintf(global_currentIP, "%d.%d.%d.%d", (UINT8)(IPTmp>>24)&0xFF, (UINT8)(IPTmp>>16)&0xFF, (UINT8)(IPTmp>>8)&0xFF, (UINT8)IPTmp&0xFF);

}

-

Thanks

-

Regards

Soumyajit

  • Hi Soumyajit,

    I am talking to our NDK expert for the API(s) that will retrieve the information that you need from NDK. I will get back to you with an answer.

    And yes, the example code will get you the IP address. Additionally, you can check 'fAdd' param to check if the IP address was added or removed.

    Vikram
  • Please see below for the answers from our NDK expert. Hope this helps.

    1.       IP address + subnet mask
     
    They can get the IP address and netmask using the NDK C configuration APIs.  Here’s some example code (for full details see ti/ndk/tools/console/conipaddr.c line 133.  This is the code for the Telnet console command for displaying IP address information):

        /* Print the IP address information only if one is present. */
        if (CfgGetImmediate( 0, CFGTAG_IPNET, if_req.index, 1, sizeof(NA), (UINT8 *)&NA) == sizeof(NA))
        {
            /* Yes the device was configured and we got the IP address/Mask */
            NtIPN2Str (NA.IPAddr, IPString);
            ConPrintf ("IP Address    : %s\n", IPString);
            NtIPN2Str (NA.IPMask, IPString);
            ConPrintf ("IP Mask       : %s\n", IPString);
        }
     
    2.      Gateway
    a.      For a static IP, this is a global variable that’s in generated .c.  They can access it via one of the NDK’s user configurable hook functions:
    char *GatewayIP   = // whatever they set in their config
     
    b.     For DHCP, the can also look at the Telnet console code for an example.  The route command displays the g/w IP via the RtGetGateIP() API:
            /* If the route is a gateway, print the gateway IP address as well */
            if( wFlags & FLG_RTE_GATEWAY )
            {
                llEnter();
                IPAddr = RtGetGateIP( hRt );
                llExit();
                NtIPN2Str( IPAddr, str );
                ConPrintf( "  %-15s  ",str);
            }
     
    3.      DNS:
     
    Again done using the C configuration APIs; they should look at the code of DNSResolveExternal() to see an example (around line 810):
     
        while( serverIdx < 4 )
        {
            rc = CfgGetImmediate( 0, CFGTAG_SYSINFO,
                                  CFGITEM_DHCP_DOMAINNAMESERVER,
                                  serverIdx, 4, (UINT8 *)&IPServer );
            if( rc != 4 )
                goto skipServer;
     
            /* Create to "to" address */
            sin.sin_addr.s_addr  = IPServer;
            sin.sin_port         = htons( DNS_PORT );
  • Hi Vikram,

    Thanks for the fast reply.

    1. Implemented, working fine

    2. a) Can you please elaborate more? Do I need to declare "char *GatewayIP;"? If yes, where? Inside "mynetworkIPAddrHook"? If yes, who will update (put values in) GatewayIP? Do I need to put the pointer to this variable anywhere in the .cfg file?

    2. b) Currently implementing

    3. I am currently using NO DHCP mode because due to some security reason the LAN DHCP have been disabled by the LAN administrator. But I'll test the DNS part (with DHCP ON) soon. Currently (with DHCP OFF), if I call "CfgGetImmediate(0, CFGTAG_SYSINFO,CFGITEM_DHCP_DOMAINNAMESERVER,1, 4,(UINT8 *)&IPTmp)" inside "mynetworkIPAddrHook" then "if(rc != 4)" is holding true, hence NO DNS. Can you please mention the CfgAddEntry() function parameters to use to insert the DNS IP in case of DHCP disabled? Do we need to call CfgGetEntry() & CfgRemoveEntry() before calling CfgAddEntry() for the DNS IP parameter insertion? Which API document / user guide documents usage of CfgXXXEntry() function/API?

    -

    Thanks

    -

    Regards

    Soumyajit

  • Soumyajit Das said:
    2. a) Can you please elaborate more? Do I need to declare "char *GatewayIP;"? If yes, where? Inside "mynetworkIPAddrHook"? If yes, who will update (put values in) GatewayIP? Do I need to put the pointer to this variable anywhere in the .cfg file?

    Are you setting up the Gateway IP statically or getting it through DHCP?

    Vikram

  • Hi Vikram,

    In my code, the DHCP is enabled by default (in the .cfg file). Based on user settings (which is stored in the EEPROM), the LAN network hook function changes the DHCP to OFF if required (see my "functionNetworkOpenHook" function given below). Section of the .cfg file is also given. Please note that the DNS IP adding part (highlighted in yellow) have been added yesterday & is not working due to some reason (which I am yet to diagnose).

    I have one doubt here, am I changing the "Ip.autoIp = true;" settings of the .cfg file to FALSE in my C code?

    SECTION OF THE .cfg FILE:

    EMAC.libType = EMAC.LibType_NonInstrumented;
    Global.IPv6 = false;
    Ip.autoIp = true;
    Ip.address = "";
    Ip.mask = "255.255.255.0";
    Ip.gatewayIpAddr = "192.168.1.2";
    Ip.domainName = "domain.com";
    var http0Params = new Http.Params();
    var http0 = Http.create(http0Params);
    Global.lowTaskPriLevel = 3;
    Global.stackInitHook = "&AddWebFiles";
    Global.stackDeleteHook = "&RemoveWebFiles";
    Global.networkIPAddrHook = "&mynetworkIPAddrHook";
    Global.networkOpenHook = "&functionNetworkOpenHook";

    SECTION of the .c FILE:

    Void functionNetworkOpenHook(Void)
    {
    char *HostName = "_csl_";
    IPN IPTmp;

    if(usr_s.eth_dhcp_enabled == true)
    {
    System_printf("NetworkOpenHook: DHCP EN\n");
    strcpy(sfdbg.buf, sys_state.timestr);

    }

    else
    {
    System_printf("NetworkOpenHook: DHCP DIS, (%s,%s,%s)\n", usr_s.eth_static_ip, usr_s.eth_subnet_mask, usr_s.eth_gateway);

    CI_IPNET NA;
    CI_ROUTE RT;

    HANDLE hCfgIpAddr, hCfg;

    /* Setup manual IP address */
    bzero(&NA, sizeof(NA));
    NA.IPAddr = inet_addr(usr_s.eth_static_ip);
    NA.IPMask = inet_addr(usr_s.eth_subnet_mask);
    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);

    // Add the default gateway.
    bzero( &RT, sizeof(RT) );
    RT.IPDestAddr = 0;
    RT.IPDestMask = 0;
    RT.IPGateAddr = inet_addr(usr_s.eth_gateway);

    hCfg = CfgNew();
    CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,
    strlen(HostName), (UINT8 *)HostName, 0 );

    // Add the route
    CfgAddEntry( hCfg, CFGTAG_ROUTE, 0, 0, sizeof(CI_ROUTE), (UINT8 *)&RT, 0 );

    // Manually add the DNS server when specified
    IPTmp = inet_addr("192.168.1.5");
    if(IPTmp)
    {
    CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER,
    0, sizeof(IPTmp), (UINT8 *)&IPTmp, 0 );
    }

    }

    }

    Regards

    Soumyajit

  • Soumyajit,

    I am working with NDK expert on your question. I will get back to you with answer.

    Vikram
  • I talked to our expert regarding your questions about DHCP and DNS. After looking into the issue, our expert recommends for that you may be better off defining the NDK stack thread yourself which will enable you have full control of the ordering of the C config API calls, as well as the special cased code for static vs. DHCP client settings.

    To define NDK stack, please follow these steps:

    1. Open <Project_Directory>\Debug\configPkg\package\cfg\<Project_name>.c file as it exists with your application's current config settings.
    2. Copy the code of the function ti_ndk_config_Global_stackThread(), and any other functions that it calls that are defined in this c file
    3. Paste this code into a new file that will be part of your application.
    4. Now you have your own copy of the stack’s main thread and config code. Edit the code to make the configurations and special cases as required.  There’s no need to do this in hook functions anymore as you have direct control of the code now.
    5. Add the following to the config file.  This causes the NDK to NOT generate the _ndk_config_Global_stackThread() function.  So it will use your copy instead:
    var Global = xdc.useModule('ti.ndk.config.Global');
    Global.stackThreadUser = '&MYMODULE_stackThreadUser'; //name of the user defined stack thread 

    Also, we see that you are creating *a second* NDK configuration in your code:

    hCfg = CfgNew();

    And you are appling the setitngs to this new configuration. We recommend that you just have a single configuration - the one created by your copy ofstackThread() above and apply all the settings to this configuration. This may solve the problems you are seeing.

    For DNS, you can add an external DNS server from the config (via the Dns module), but this is only supported for statically configured IP addresses. Since you are configured for DHCP by default, you should just use the C config API to do this into your copy of the stackThread(). The code would be similar to this:

    /* function to specify an external DNS server */
    Void ti_ndk_config_external_dns_init(HANDLE hCfg)
    {
        IPN IPTmp = inet_addr("`Dns.externDnsServIp`");
        if (IPTmp) {
            CfgAddEntry(hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER,
                0, sizeof(IPTmp), (UINT8 *)&IPTmp, 0);
        }
    }

    Hope we answered your questions. Please mark this thread answered if you have all the information you need.

    Thanks,

    Vikram

  • Hi Vikram,

    Thanks for your reply.

    Firstly, "var Global = xdc.useModule('ti.ndk.config.Global');" is already there in the .cfg file, so I tried to add "Global.stackThreadUser='&sd___ti_ndk_config_Global_stackThread';". Now, the compiler saying "XDC runtime error: ti.ndk.config.Global: no element named 'stackThreadUser'"

    Secondly, I would like to avoid having the "ti_ndk_config_Global_stackThread" function contents in my project & let it be where it is (I prefer not to touch any TI made driver). Rather, I would prefer fetching the NDK configuration and changing it accordingly.

    Still if you want, I can test the "stackThreadUser" error in finding out why it's not working as expected.

    Regarding, DNS IP, let us discuss it on the other thread which I have earlier opened exclusively to keep the DNS IP (NO DHCP mode) separate from the DHCP mode ON discussion on this thread.

    For the time being, can you please help me in getting the DNS IP that the NDK have received from the DHCP server (in a DHCP enabled condition)? What I mean is that, while DHCP is enabled, I want to know the DNS IP that the NDK have got from the Auto IP allocating server.

    -

    Thanks

    -

    Regards

    Soumyajit

  • Hi Soumyajit,

    We recommend defining your own "ti_ndk_config_Global_stackThread" as hook functions may be able to provide the complex functionality needed for your use case. You would get better configuration flexibility with this function.

    Regarding the error, this feature was added in the NDK 2.24.00.11. So, is it possible to move your application to a new version of NDK?

    Thanks,
    Vikram
  • Hi Vikram,

      Thanks for the suggestion. Can you brief on how to change the NDK package? I have two directories in "C:\ti\", one is "tirtos_tivac_2_01_00_03" & other one is "tirtos_tivac_2_10_01_38". Now inside "tirtos_tivac_2_01_00_03" directory, we have "ndk_2_23_01_01" & inside "tirtos_tivac_2_10_01_38" directory we have "ndk_2_24_01_18". Now, how do I change the NDK to version "ndk_2_24_01_18"? Do I need to change TI RTOS too to the new version? I tried changing the TI RTOS directly from "ProjectExplorer->ProjectName->Properties(ByRightClick)->General->RTSCtab->TI RTOS for Tiva C->2.10.1.38(selectByCheckBox)". But this is causing the IDE to throw up a list a errors as given below. Can we change the NDK version only without changing the TI RTOS version?

    -

    Description Resource Path Location Type
    unresolved symbol SDSPI_config, first referenced in C:\ti\tirtos_tivac_2_10_01_38\packages\ti\drivers\lib\drivers_tivaware.aem4f<SDSPI.oem4f> DL_Tiva_v2 C/C++ Problem
    unresolved symbol NIMUDeviceTable, first referenced in C:\ti\tirtos_tivac_2_10_01_38\products\ndk_2_24_01_18\packages\ti\ndk\stack\lib\stk.aem4f<nimu.oem4f> DL_Tiva_v2 C/C++ Problem
    unresolved symbol TM4C_initI2C, first referenced in ./fatsdusbcopy.obj DL_Tiva_v2 C/C++ Problem
    unresolved symbol SPI_config, first referenced in C:\ti\tirtos_tivac_2_10_01_38\packages\ti\drivers\lib\drivers_tivaware.aem4f<SPI.oem4f> DL_Tiva_v2 C/C++ Problem
    unresolved symbol TM4C_initUART, first referenced in ./fatsdusbcopy.obj DL_Tiva_v2 C/C++ Problem
    unresolved symbol TM4C_initSPI, first referenced in ./fatsdusbcopy.obj DL_Tiva_v2 C/C++ Problem
    unresolved symbol USBMSCHFatFs_config, first referenced in C:\ti\tirtos_tivac_2_10_01_38\packages\ti\drivers\lib\drivers_tivaware.aem4f<USBMSCHFatFs.oem4f> DL_Tiva_v2 C/C++ Problem
    unresolved symbol UART_config, first referenced in C:\ti\tirtos_tivac_2_10_01_38\packages\ti\drivers\lib\drivers_tivaware.aem4f<UART.oem4f> DL_Tiva_v2 C/C++ Problem
    unresolved symbol EK_TM4C1294XL_initGPIO, first referenced in ./fatsdusbcopy.obj DL_Tiva_v2 C/C++ Problem
    unresolved symbol EK_TM4C1294XL_initEMAC, first referenced in ./fatsdusbcopy.obj DL_Tiva_v2 C/C++ Problem
    unresolved symbol EK_TM4C1294XL_initUSBMSCHFatFs, first referenced in ./fatsdusbcopy.obj DL_Tiva_v2 C/C++ Problem
    unresolved symbol EK_TM4C1294XL_initSDSPI, first referenced in ./fatsdusbcopy.obj DL_Tiva_v2 C/C++ Problem
    unresolved symbol I2C_config, first referenced in C:\ti\tirtos_tivac_2_10_01_38\packages\ti\drivers\lib\drivers_tivaware.aem4f<I2C.oem4f> DL_Tiva_v2 C/C++ Problem
    unresolved symbol GPIO_config, first referenced in C:\ti\tirtos_tivac_2_10_01_38\packages\ti\drivers\lib\drivers_tivaware.aem4f<GPIOTiva.oem4f> DL_Tiva_v2 C/C++ Problem
    <a href="file:/c:/ti/ccsv6/tools/compiler/dmed/HTML/10234.html">#10234-D</a> unresolved symbols remain DL_Tiva_v2 C/C++ Problem
    #10010 errors encountered during linking; "DL_Tiva_v2.out" not built DL_Tiva_v2 C/C++ Problem

    -

    Regards

    Soumyajit

  • Hi Soumyajit,

    NDK 2.24.01.18 has dependency on SYS/BIOS 6.37.02.27 (software-dl.ti.com/.../ndk_2_24_01_18_release_notes.html) which would require you to move to SYS/BIOS 6.37.02.27 (or TI-RTOS 2.10.01.38).

    Regarding the errors, there were changes in SDSPI drivers as noted in the release notes (software-dl.ti.com/.../tirtos_2_10_01_38_release_notes.html which is causing the build errors.
  • Hi Vikram,

    I am attempting to shift to TI RTOS v2.10.1.38. Now, as you said that there are some upgrade in the SDSPI driver, I followed your given link to know the changes effective. But the link only states "SDSPI: SDSPITiva_HWAttrs, SDSPIUSCIA_HWAttrs, and SDSPIUSCIB_HWAttrs structures changed. Please refer to the new structure definition and change your code as needed." under Section "Upgrade and Compatibility Information".

    Now, where will I find the "new structure definition"? Where are the documents available? Can you refer me to some link(s) for the same? Is there any document on Migrating from one TI-RTOS version to another?

    -

    Thanks

    -

    Regards

    Soumyajit

  • Hi Soumyajit,

    If you are migrating to a newer version, I would recommend the latest version of TI-RTOS for Tiva: software-dl.ti.com/.../index.html .

    Regarding the TI-RTOS migration, we generally make a note of the steps in this wiki: processors.wiki.ti.com/.../TI-RTOS_Support .
    Though, I am unable to find the 2.10.1.38 migration steps. I will check with the team for the documentation. Meanwhile, you can create an example application with the new TI-RTOS and compare the <Tiva_board>.c, <Tiva_board>.h and Board.h files with the ones in your application. This would show you the changes in the SDSPI structure.

    Vikram
  • Hi Vikram,

    Since the original topic of this thread is resolved, I am closing this thread.

    Regarding migration to a new NDK/TI-RTOS, I will try it out sometime later, atleast not immediately!!

    -

    Thanks

    -

    Regards

    Soumyajit