Tool/software: TI-RTOS
As the topic says I have problem with HTTPCli_connect when using static IP, but if DHCP is defined it works. I have checked the communication with the Wireshark and if I use static ip it doesn't even send anything with the HTTPCli_connect. HTTPCli_initSockAddr works perfectly, means it gets the IP address from hostname from the manual defined DNS server. Below the code.
TI-RTOS: 2.16.1.14
XDCTools: 3.32.0.06
NDK: 2.25.00.09
Ip.autoIp = true; is always configured and will be turned off later when configuring the static IP.
/* ================ NDK configuration ================ */
var Ndk = xdc.loadPackage('ti.ndk.config');
var Global = xdc.useModule('ti.ndk.config.Global');
var Ip = xdc.useModule('ti.ndk.config.Ip');
var Tcp = xdc.useModule('ti.ndk.config.Tcp');
Global.IPv6 = false;
Global.stackLibType = Global.MIN;
Global.networkOpenHook = "&TcpHooks_vNetOpenHook";
Global.networkIPAddrHook = "&TcpHooks_vIPAddrHook";
/* automatically call fdOpen/CloseSession for our sockets Task */
Global.autoOpenCloseFD = true;
Global.pktNumFrameBufs = 10;
Global.memRawPageCount = 6;
Global.ndkThreadStackSize = 1536;
Global.lowTaskStackSize = 1024;
Global.normTaskStackSize = 1024;
Global.highTaskStackSize = 1024;
Tcp.transmitBufSize = 1024;
Tcp.receiveBufSize = 1024;
Ip.autoIp = true;
/* ================ HTTP configuration ================ */
var Http = xdc.useModule('ti.net.http.Http');
Http.networkStack = Http.NDK;
void TcpHooks_vNetOpenHook(void)
{
IPN IPTmp;
CI_IPNET NA;
HANDLE hCfgIpAddr;
HANDLE hCfg;
int ret;
bIPAddressChanged();
hCfg = CfgGetDefault();
if (!hCfg)
{
System_abort("Couldn't fetch handle\n");
}
ret = CfgGetEntryCnt(hCfg, CFGTAG_IPNET, 1);
System_printf("Static IP count: %d\n", ret);
/* get the current static IP entry */
if (CfgGetEntry(hCfg, CFGTAG_IPNET, 1, 1, &hCfgIpAddr))
{
/* remove the current static IP entry */
if (CfgRemoveEntry(hCfg, hCfgIpAddr) < 0)
{
System_abort("Couldn't remove static IP entry\n");
}
}
else
{
System_printf("Couldn't get static IP entry\n");
}
// Manually add the DNS server when specified
IPTmp = inet_addr(strDnsAddr);
if (IPTmp)
{
if (CfgAddEntry(hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER,
0, sizeof(IPTmp), (UINT8 *)&IPTmp, 0 ) < 0)
{
System_abort("Couldn't add static IP entry\n");
}
}
else
{
System_printf("Couldn't add DNS IP\n");
}
/* Setup manual IP address */
bzero(&NA, sizeof(NA));
NA.IPAddr = inet_addr(strIpAddr);
NA.IPMask = inet_addr(strIpMask);
strcpy(NA.Domain, "own.com");
NA.NetType = 0;
/* add a new static IP entry */
if (CfgAddEntry(hCfg, CFGTAG_IPNET, 1, 0,
sizeof(CI_IPNET), (UINT8 *)&NA, 0) < 0)
{
System_abort("Couldn't add static IP entry\n");
}
}
void TcpHooks_vIPAddrHook(IPN IPAddr, uint IfIdx, uint fAdd)
{
IPN IPTmp;
CI_IPNET NA;
HANDLE hCfg;
int rc = 0;
char IPString[16];
hCfg = CfgGetDefault();
/* Initialize the IP Address block. */
bzero(&NA, sizeof(CI_IPNET));
if (fAdd)
{
System_printf("networkIPAddrHook: Network Added\n");
Semaphore_post(semaphoreNdkStack);
}
else
{
System_printf("networkIPAddrHook: Network Removed\n");
}
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);
/* Print the IP address information only if one is present. */
if (CfgGetImmediate(hCfg, CFGTAG_IPNET, 1, 1, sizeof(NA), (UINT8 *)&NA) == sizeof(NA))
{
/* Yes the device was configured and we got the IP address/Mask */
NtIPN2Str (NA.IPAddr, IPString);
System_printf("IP Address: %s\n", IPString);
NtIPN2Str (NA.IPMask, IPString);
System_printf("IP Subnet Mask: %s\n", IPString);
}
else
{
System_printf("IP Address & SUBNET MASK NOT AVAILABLE\n");
}
rc = CfgGetImmediate(hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER,
1, 4, (UINT8 *)&IPTmp );
if (rc == 4)
{
IPTmp = ntohl(IPTmp);
System_printf("networkIPAddrHook:\tIf-%d: DNS = %d.%d.%d.%d\n", IfIdx,
(UINT8)(IPTmp>>24)&0xFF, (UINT8)(IPTmp>>16)&0xFF,
(UINT8)(IPTmp>>8)&0xFF, (UINT8)IPTmp&0xFF);
}
else
{
System_printf("networkIPAddrHook: DNS IP Fetch Failed!!\n");
}
}
void Cloud_vWork(void)
{
struct sockaddr_in addr;
char cContentLength[5];
int count;
int ret;
int dataSize = 64;
int offset;
HTTPCli_Struct cli;
HTTPCli_Field fields[2] =
{
{ HTTPStd_FIELD_NAME_HOST, HOSTNAME },
{ NULL, NULL }
};
Semaphore_pend(semaphoreNdkStack, 10000); // wait 10 s for the stack to initialize and get ip
fdOpenSession(Task_self()); // open the NDK file descriptor session for this thread
HTTPCli_construct(&cli);
HTTPCli_setRequestFields(&cli, fields);
while (1)
{
System_printf("Sending a HTTP PUT request to '%s'\n", HOSTNAME);
ret = HTTPCli_initSockAddr((struct sockaddr *)&addr, HOSTNAME, 0);
if (ret < 0) {
printError("httpTask: address resolution failed", ret);
continue;
}
ret = HTTPCli_connect(&cli, (struct sockaddr *)&addr, 0, NULL);
if (ret < 0) {
printError("httpTask: connect failed", ret);
continue;
}
Task_sleep(FIVE_MINUTES);
}
}
Everything works if I comment everything out from the TcpHooks_vNetOpenHook. I have followed with the debugger from the HTTPCli_connect, which is not easy from optimized code, to place where it just can't find the route to the destination. What could be the reason?
BR
JHi