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.

How to config external DSN server for NDK

TivaC tirtos_tivac_2_10_01_38 ndk_2_24_01_18 CCS6.0

I am using static configuration for my IPv4. If I want to create a socket with a server by its name, I think I need to config the DNS server and get the IP by "DNSGetHostByName", but I didn't find where to set the DNS server.

I think the setting in "TI-RTOS->Product->NDK->Application Layer->DNS-Module Setting" is not for this purpose. Its purpose is to make TivaC as a DSN server. Am I right?

I didn't find a thread that addresses this.

Thanks.

  • Hi Jianyi,

    You can configure the external DNS server address by setting the "External DNS server address" in XGConf's "TI-RTOS->Products->NDK->Application Layer->DNS-Module Settings" page. It will not make the TivaC a DNS server. In order to make it a DNS server you need to add a new DNS server instance in the "Instance" tab.

    Best,

    Ashish

  • Thanks. I have two questions:
    1. After enabling "Add the Dns server module to my configuration", building will fail:
    Error: library "C:\ti\tirtos_tivac_2_10_01_38\products\ndk_2_24_01_18\packages\ti\ndk\config\..\stack\lib\stk_nat.aem4f" does not exist. Please follow the steps to build this NDK library at processors.wiki.ti.com/.../Rebuilding_The_NDK_Core_Using_Gmake
    2. How to make the DSN server configurable, such as from config data in EEPROM?
  • I managed to solve the above two issues:
    1. Rebuild NDK according to the guide.
    2. Use hook function to add DSN at run time from configuration data, such as from EEPROM. The following is the code in the auto generated file "\configPkg\package\cfg\APmain_pem4f.c" corresponding to file "APmain_pem4f.cfg".

    /* Create and build the system configuration from scratch. */
        hCfg = CfgNew();
        if (!hCfg) {
            xdc_runtime_System_printf("Unable to create configuration\n");
            goto main_exit;
        }
    
        {
            extern Void HookFuncSetIpAddress();
    
            /* call user defined stack initialization hook */
            HookFuncSetIpAddress(hCfg);		//#### Here add my own DNS server using similar code in "ti_ndk_config_external_dns_init"
        }
    
        /* add the Ip module configuration settings. */
        ti_ndk_config_ip_init(hCfg);
    
        /* add the Tcp module configuration settings. */
        ti_ndk_config_tcp_init(hCfg);
    
        /* add the Udp module configuration settings. */
        ti_ndk_config_udp_init(hCfg);
    
        /* add the external DNS server to the configuration. */
        ti_ndk_config_external_dns_init(hCfg);	//### DSN server in the cfg file is added here
    
        /* add the configuration settings for NDK low priority tasks stack size. */
        rc = 5120;
        CfgAddEntry(hCfg, CFGTAG_OS, CFGITEM_OS_TASKSTKLOW,
                     CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
    
        /* add the configuration settings for NDK norm priority tasks stack size. */
        rc = 5120;
        CfgAddEntry(hCfg, CFGTAG_OS, CFGITEM_OS_TASKSTKNORM,
                     CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
    
        /*
         *  Boot the system using this configuration
         *
         *  We keep booting until the function returns 0. This allows
         *  us to have a "reboot" command.
        */
        do
        {
            rc = NC_NetStart(hCfg, ti_ndk_config_Global_NetworkOpen, 
                             ti_ndk_config_Global_NetworkClose, 
                             ti_ndk_config_Global_NetworkIPAddr);
        } while( rc > 0 );
    
        /* Delete Configuration */
        CfgFree(hCfg);

    However, in this way, the default DSN from cfg file is always added (because the hook function is called just after "CfgNew", so we could not call "CfgRemoveEntry" to remove the configurations that are added by default code), which is usually useless, although not harmful in this case (simply another DNS server).

    So is there a way to make this function "ti_ndk_config_Global_stackThread" more customisable? For example, I may want to config it to enable DHCP, or use static IP, according to my setting data at run time.

    Thanks

  • I have tried using link option "--symbol_map=ti_ndk_config_ip_init=ti_ndk_config_ip_init_customer" to replace function "ti_ndk_config_ip_init" by "ti_ndk_config_ip_init_customer", but link will fail:

    error #10268-D: symbol "ti_ndk_config_ip_init" is mapped to symbol "ti_ndk_config_ip_init_customer"; mapped symbol cannot have definition and reference in the same file

    As function "ti_ndk_config_ip_init" is defined and as well as referred in the auto generated file, option "--symbol_map" will never be able to work for this function. Any way out?

    Thanks
  • Or is there a way to make compiler/linker skip the auto generated file? I could copy the auto generated file to somewhere else and modify it according to my need. If the original file could be skipped, link should succeed finally. The solution is acceptable for me.
  • Or can I change the configuration after NDK is started?

  • Hi Jianyi,

    Jianyi Bao said:

    2. Use hook function to add DSN at run time from configuration data, such as from EEPROM. The following is the code in the auto generated file "\configPkg\package\cfg\APmain_pem4f.c" corresponding to file "APmain_pem4f.cfg".

    /* Create and build the system configuration from scratch. */
        hCfg = CfgNew();
        if (!hCfg) {
            xdc_runtime_System_printf("Unable to create configuration\n");
            goto main_exit;
        }
    
        {
            extern Void HookFuncSetIpAddress();
    
            /* call user defined stack initialization hook */
            HookFuncSetIpAddress(hCfg);		//#### Here add my own DNS server using similar code in "ti_ndk_config_external_dns_init"
        }
    
        /* add the Ip module configuration settings. */
        ti_ndk_config_ip_init(hCfg);
    
        /* add the Tcp module configuration settings. */
        ti_ndk_config_tcp_init(hCfg);
    
        /* add the Udp module configuration settings. */
        ti_ndk_config_udp_init(hCfg);
    
        /* add the external DNS server to the configuration. */
        ti_ndk_config_external_dns_init(hCfg);	//### DSN server in the cfg file is added here
    
        /* add the configuration settings for NDK low priority tasks stack size. */
        rc = 5120;
        CfgAddEntry(hCfg, CFGTAG_OS, CFGITEM_OS_TASKSTKLOW,
                     CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
    
        /* add the configuration settings for NDK norm priority tasks stack size. */
        rc = 5120;
        CfgAddEntry(hCfg, CFGTAG_OS, CFGITEM_OS_TASKSTKNORM,
                     CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
    
        /*
         *  Boot the system using this configuration
         *
         *  We keep booting until the function returns 0. This allows
         *  us to have a "reboot" command.
        */
        do
        {
            rc = NC_NetStart(hCfg, ti_ndk_config_Global_NetworkOpen, 
                             ti_ndk_config_Global_NetworkClose, 
                             ti_ndk_config_Global_NetworkIPAddr);
        } while( rc > 0 );
    
        /* Delete Configuration */
        CfgFree(hCfg);

    However, in this way, the default DSN from cfg file is always added (because the hook function is called just after "CfgNew", so we could not call "CfgRemoveEntry" to remove the configurations that are added by default code), which is usually useless, although not harmful in this case (simply another DNS server).

    So is there a way to make this function "ti_ndk_config_Global_stackThread" more customisable? For example, I may want to config it to enable DHCP, or use static IP, according to my setting data at run time.

    Which file are you modifying here to add your SetIP hook function ? Also, are you still using XGConf (GUI cfg editor) to configure NDK ?

    Best,

    Ashish

  • I am using XGCONF. This tool will generate file "\configPkg\package\cfg\APmain_pem4f.c", in which some hook function is allowed to be inserted, like the one above:
    {
    extern Void HookFuncSetIpAddress();

    /* call user defined stack initialization hook */
    HookFuncSetIpAddress(hCfg); //#### Here add my own DNS server using similar code in "ti_ndk_config_external_dns_init"
    }

    HookFuncSetIpAddress is a function defined in my own code, where I can customize some settings.
  • Hi Jianyi,

    Reading your newer posts I realize you are trying to modify the generated C file in your project. Is that correct ? If yes, please avoid doing that. It is not a good idea to modify the generated C files.

    I would recommend only using XGConf (the GUI cfg editor) to configure NDK.

    Best,
    Ashish
  • I don't like to modify the generated file directly, and I understand it is not a good idea. But my question is that XGCONF can't configure the NDK flexibly enough. It will configure the NDK:
    1. Use DHCP or static IP. I have to choose one of them. To change the choice, I have to download a new code into the device.
    2. Add a DNS server whose IP is fixed in the configuration. To change the address, I have to download a new code.

    My requirements are:
    1. I have saved some settings in EEPROM, which could be modified by another external PC tool.
    2. In the settings, I could set the device to use DHCP, or use static IP. So the code must be able to set the device to enable DHCP or not at runtime.
    3. And I could also change the DNS server in the settings. So the code must be able to set DNS from my setting data at runtime.
  • Jianyi Bao said:

    My requirements are:
    1. I have saved some settings in EEPROM, which could be modified by another external PC tool.
    2. In the settings, I could set the device to use DHCP, or use static IP. So the code must be able to set the device to enable DHCP or not at runtime.
    3. And I could also change the DNS server in the settings. So the code must be able to set DNS from my setting data at runtime.

    You can change the various NDK settings at runtime using the configuration manager APIs. Check out the "Legacy Configuration Manager API" section of the NDK API reference guide (http://www.ti.com/lit/ug/spru524i/spru524i.pdf).

    Best,

    Ashish

  • Thanks. I assume the steps should be like this:
    1. Wait for NDK to start.
    2. In my own code in another task, call "CfgGetDefault()" to get the HANDLE of the current active configuration.
    3. Call "CfgAddEntry()" and "CfgRemoveEntry()" as necessary, for my own configuration.

    So please help for the following questions:
    1. Are the above steps correct?
    2. According to the reference guide, the change of the configuration will take effect immediately if it is active. So I don't need to do something else, right?
    3. I am doing the modifications in another task, so is it thread safe?
  • Hi Ashish

    Could you please take a look at my questions? Thank you so much.

  • Hi Jianyi,

    Sorry for the late response. The steps you listed look correct.

    Jianyi Bao said:

    3. I am doing the modifications in another task, so is it thread safe?

    It is ok to update the configuration from another task. You should just be careful that the configuration is not modified while network transactions or some other network operations are underway. If for instance you change the IP while a TCP transaction is underway, then the transaction could fail.

    Best,

    Ashish

  • Hi, Ashish,
    Thanks so much for your answers. Now I could reconfig my network interface.