Hello,
I have been trying to set up a DNS client on EK-TM4C1294XL for a week now. I have recompiled NDK to support everything and tried seemingly every possible combination of the NDK modules.
I use a DHCP client to get my IP, which works well. I have successfully connected to a secure server using wolfSSL via a hardcoded IP address and I can ping my device on the local network. The only problem I have is that DNSGetHostByName() always returns NODNSREPLY (19). Although I have spent countless hours trying to find a solution or even example code to verify against, I have so far come up with nothing and am slowly getting desperate.
Below is my .cfg file, excerpts of the code I use and the Global Service Report output:
NOTE that my config file has gone through numerous changes over the past week.
/* ================ General configuration ================ */ var Defaults = xdc.useModule('xdc.runtime.Defaults'); var Diags = xdc.useModule('xdc.runtime.Diags'); var Error = xdc.useModule('xdc.runtime.Error'); var Log = xdc.useModule('xdc.runtime.Log'); var Main = xdc.useModule('xdc.runtime.Main'); var Memory = xdc.useModule('xdc.runtime.Memory'); var System = xdc.useModule('xdc.runtime.System'); var Text = xdc.useModule('xdc.runtime.Text'); var BIOS = xdc.useModule('ti.sysbios.BIOS'); var Clock = xdc.useModule('ti.sysbios.knl.Clock'); var Task = xdc.useModule('ti.sysbios.knl.Task'); var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore'); var Hwi = xdc.useModule('ti.sysbios.hal.Hwi'); var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem'); var Global = xdc.useModule('ti.ndk.config.Global'); var Tcp = xdc.useModule('ti.ndk.config.Tcp'); var Ip = xdc.useModule('ti.ndk.config.Ip'); var Emac = xdc.useModule('ti.ndk.config.Emac'); var Udp = xdc.useModule('ti.ndk.config.Udp'); var Dns = xdc.useModule('ti.ndk.config.Dns'); var DhcpClient = xdc.useModule('ti.ndk.config.DhcpClient'); Global.enableCodeGeneration = true; // Global.enableCodeGeneration = {true or false}; /* * Program.stack is ignored with IAR. Use the project options in * IAR Embedded Workbench to alter the system stack size. */ if (!Program.build.target.$name.match(/iar/)) { /* * Reducing the system stack size (used by ISRs and Swis) to reduce * RAM usage. */ Program.stack = 2048; } /* ================ System configuration ================ */ var SysMin = xdc.useModule('xdc.runtime.SysMin'); System.SupportProxy = SysMin; /* Enable Semihosting for GNU targets to print to CCS console */ if (Program.build.target.$name.match(/gnu/)) { var SemiHost = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport'); } /* ================ Logging configuration ================ */ var LoggingSetup = xdc.useModule('ti.uia.sysbios.LoggingSetup'); /* ================ Kernel configuration ================ */ /* Use Custom library */ var BIOS = xdc.useModule('ti.sysbios.BIOS'); BIOS.libType = BIOS.LibType_Instrumented; BIOS.logsEnabled = true; BIOS.assertsEnabled = true; var task0Params = new Task.Params(); task0Params.instance.name = "heartBeat"; task0Params.arg0 = 1000; task0Params.stackSize = 512; Program.global.heartBeatTask = Task.create("&heartBeatFxn", task0Params); /* ================ Driver configuration ================ */ var TIRTOS = xdc.useModule('ti.tirtos.TIRTOS'); TIRTOS.useGPIO = true; BIOS.heapSize = 90112; Global.networkIPAddrHook = "&netIPAddrHook"; Global.stackLibType = Global.PPP_PPPOE; Global.IPv6 = false; TIRTOS.libType = TIRTOS.LibType_Instrumented; Ip.DHCPOPT_NAME_SERVERS = true; Udp.receiveBufSize = 4096; Ip.ResolveIP = false; Ip.dhcpClientMode = 9; Dns.externDnsServIp = "192.168.8.1"; Ip.IfIdXValid = true; Ip.mask = "255.255.255.0"; Ip.enableForwarding = true; Ip.enableFiltering = true; Ip.RestartIPTerm = true;
void getServerIPTask(UArg arg0, UArg arg1) { while (1) { uint8_t ret = DNSGetHostByName("www.google.com", &host, sizeof(host)); // HOSTENT host is defined globally System_printf("RET %d\n", ret); System_flush(); Task_sleep(1000); } } /* * ======== netIPAddrHook ======== * This function is called when IP Addr is added/deleted */ void netIPAddrHook(unsigned int IPAddr, unsigned int IfIdx, unsigned int fAdd) { static Task_Handle taskHandle; Task_Params taskParams; Error_Block eb; if (fAdd && !taskHandle) { Error_init(&eb); Task_Params_init(&taskParams); taskParams.stackSize = HTTPTASKSTACKSIZE; taskParams.priority = 7; taskHandle = Task_create((Task_FuncPtr)getServerIPTask, &taskParams, &eb); if (taskHandle == NULL) { printError("netIPAddrHook: Failed to create HTTP Task\n", -1); } } } /* * ======== main ======== */ int main(void) { /* Call board init functions */ Board_initGeneral(); Board_initEMAC(); Board_initGPIO(); /* Turn on user LED */ GPIO_write(Board_LED0, Board_LED_ON); System_printf("Starting the example\nSystem provider is set to SysMin. " "Halt the target to view any SysMin contents in ROV.\n"); /* SysMin will only print to the console when you call flush or exit */ System_flush(); /* Start BIOS */ BIOS_start(); return (0); }
The auto generated Service Report code should start the DNS client when an IP address is assgined:
Void ti_ndk_config_Global_serviceReport(uint Item, uint Status, uint Report, HANDLE h) { xdc_runtime_System_printf("Service Status: %-9s: %-9s: %-9s: %03d\n", TaskName[Item-1], StatusStr[Status], ReportStr[Report/256], Report&0xFF); if (Item == CFGITEM_SERVICE_DHCPCLIENT && Status == CIS_SRV_STATUS_ENABLED && (Report == (NETTOOLS_STAT_RUNNING|DHCPCODE_IPADD) || Report == (NETTOOLS_STAT_RUNNING|DHCPCODE_IPRENEW)) ) { /* add the external DNS server to the configuration. */ ti_ndk_config_external_dns_init(h); } xdc_runtime_System_flush(); }
And the Service Report's output:
Using MAC address in flash Starting the 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:192.168.8.108 RET 19 Service Status: DHCPC : Enabled : Running : 017 RET 19 RET 19 RET 19 RET 19 RET 19
Regards,
Jaan