Part Number: CC3200-LAUNCHXL
Other Parts Discussed in Thread: CC3200
Tool/software: TI-RTOS
hi
I want to implement an https client on my device to connect to a server of the following format : [subdomain].firebaseio.com
I was successful in doing so with the cc3200 sdk example-http client demo, by adding corresponding mask, method and certificate.
But when it come to tirtos --
The httpcli.h and httpcli.c file are different. The httpcli.h file has a provided example in it as follows:
// Make HTTP 1.1 POST request
* //
* // Send request to the server:
* //
* // POST /index.html HTTP/1.1
* // Host: www.example.com
* HTTPCli_sendRequest(&cli, HTTPStd_POST, "/index.html", true);
*
* // Send additional fields
* //
* // Content-Length: <length>
* // <blank line>
* HTTPCli_sendField(&cli, HTTPStd_FIELD_NAME_CONTENT_LENGTH, len, true);
*
* // Send request body
* //
* // <data>
* HTTPCli_sendRequestBody(&cli, data, strlen(data));
*
* // Get the processed response status
* //
* // HTTP/1.1 200 OK
* status = HTTPCli_getResponseStatus(&cli);
*
* // Check the HTTP return status and process remaining response
* if (status == HTTPStd_OK) {
* do {
* // Filter the response headers and get the set response field
* //
* //...
* // Content-type: text/xml; charset=utf-8\r\n
* // Content-length: 34
* // ...
* ret = HTTPCli_getResponseField(&cli, buf, sizeof(buf), &moreFlag);
*
* // Process data in buf if field is content length
* // Zero is the index of Content length in respFields array
* if (ret == 0) {
* len = (int)strtoul(buf, NULL, 0);
* }
*
* } while (ret != HTTPCli_FIELD_ID_END);
*
* while (len > 0) {
* len -= HTTPCli_readRawResponseBody(&cli, buf, sizeof(buf));
* // ... process buf data and save ...
* }
* }
*
* HTTPCli_disconnect(&cli);
*
* HTTPCli_destruct(&cli);
But the sssl.h file in not found in the tirtos folders. TIRTOS VERSION: tirtos_cc32xx_2_16_01_14
I believe we have to use tls.h file for this, I tried with the following code , BUT STILL GETTING ERROR
HTTPCli_Struct cli;
HTTPCli_Params cli_param;
// Request fields
HTTPCli_Field fields[4] = {
{HTTPCli_FIELD_NAME_HOST, HOST_NAME},
{HTTPCli_FIELD_NAME_ACCEPT, "*/*"},
{HTTPCli_FIELD_NAME_CONTENT_LENGTH, "0"},
{NULL, NULL}
};
// Response field filters
const char *respFields[2] = {
HTTPStd_FIELD_NAME_CONTENT_LENGTH,
NULL
};
const char *ids[4] = {
HTTPCli_FIELD_NAME_CONTENT_LENGTH,
HTTPCli_FIELD_NAME_CONNECTION,
HTTPCli_FIELD_NAME_CONTENT_TYPE,
NULL
};
bool moreFlag;
long lRetVal = -1;
struct sockaddr_in addr;
lRetVal = sl_NetAppDnsGetHostByName((signed char *)HOST_NAME,
strlen((const char *)HOST_NAME),
&g_ulDestinationIP,SL_AF_INET);
if(lRetVal < 0)
{
ASSERT_ON_ERROR(lRetVal);
}
UART_PRINT("dnsipget=%d\n\r",lRetVal);
addr.sin_family = AF_INET;
addr.sin_port = htons(HOST_PORT);
addr.sin_addr.s_addr = sl_Htonl(g_ulDestinationIP);
SlDateTime_t dt;
// /* Set current Date to validate certificate */
dt.sl_tm_day = 4;
dt.sl_tm_mon = 1;
dt.sl_tm_year = 2017;
dt.sl_tm_hour = 9;
dt.sl_tm_min = 39;
dt.sl_tm_sec = 00;
sl_DevSet(SL_DEVICE_GENERAL_CONFIGURATION,
SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME,
sizeof(SlDateTime_t), (unsigned char *)(&dt));
TLS_Handle tls;
#define SL_CA_CERT "cert1.cer"
struct TLS_Params params;
TLS_Params_init(¶ms);
char storage[10];
memset(storage,0,10);
memcpy(storage,SL_CA_CERT,strlen(SL_CA_CERT));
params.ca=storage;
UART_PRINT("params.ca=%s\n\r",params.ca);
params.calen=strlen(SL_CA_CERT);
UART_PRINT("params.calen=%d\n\r",params.calen);
*(params.ca+params.calen)='\0';
tls=TLS_create(TLS_METHOD_CLIENT_TLSV1_2,¶ms,"cert");
if(tls==NULL)
{
UART_PRINT("NULL");
}
else
{
UART_PRINT("TLS HANDLE not null==>");
UART_PRINT("tls handle=%p\n\r",tls);
}
cli.tls=tls;
cli_param.tls=tls;
cli_param.timeout=20;
UART_PRINT("cli.tls=%p\n\r",cli.tls);
// Construct a static HTTP client instance
HTTPCli_construct(&cli);
// Connect to the HTTP Server
lRetVal=HTTPCli_connect(&cli, (struct sockaddr *)&addr,HTTPCli_TYPE_TLS,&cli_param);
if(lRetVal<0)
{
UART_PRINT("lRetVal=%d",lRetVal);
UART_PRINT("not connected\n\r");
}
THE OUTPUT ERROR IS:
HTTP Get Begin: dnsipget=0 params.ca=cert1.cer params.calen=9 TLS HANDLE not null==>tls handle=2001b440 cli.tls=2001b440 lRetVal=-102not connected connectval=-102sendreq=-103status=-104HTTP Get failed. HTTP Get End:
Could you guide me on this
Thanks
av