Hi chrisc,
Thanks For Your Reply.
From GITHUB I got code "tcpEcho_Client_TivaTM4C1294NCPDT" Example code. What i needed. so i made changes according to that example.
But still i got error while wolfSSL_connect(). so As per your suggestion Here i send my Debug log Please Check it.
====> tcpclient: wolfSSL_CTX_new Success
====> tcpclient: loading ca_cert_der_2048 Success
====> tcpclient: loading client_cert_der_2048 Success
====> tcpclient: loading client_key_der_2048 Success
====> tcpclient: tcpHandler: wolfSSL_new Success
====> tcpclient: looked for: {1}
====> tcpclient: return was: {-1}
====> tcpclient: wolfSSL error: {-326}
====> tcpclient: wolfSSL error string: {no support for error strings built in}
Below is my updated code.
Void tcpClientTaskFxn(UArg arg0, UArg arg1)
{
int sockfd;
int ret;
struct sockaddr_in servAddr;
Error_Block eb;
bool flag = true;
bool internal_flag = true;
int nbytes;
char *buffer;
char msg[] = "Hello from TM4C1294XL Connected Launchpad";
WOLFSSL* ssl = (WOLFSSL *) arg0;
fdOpenSession(TaskSelf());
Task_sleep(7000);
wolfSSL_Init();
WOLFSSL_CTX* ctx = NULL;
ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
if (ctx == 0)
{
System_printf("tcpHandler: wolfSSL_CTX_new error.\n");
exitApp(ctx);
}
else
{
System_printf("====> tcpclient: wolfSSL_CTX_new Success \r\n");
}
if (wolfSSL_CTX_load_verify_buffer(ctx, ca_cert_der_2048, sizeof(ca_cert_der_2048) / sizeof(char), SSL_FILETYPE_ASN1) != SSL_SUCCESS)
{
System_printf("tcpHandler: Error loading ca_cert_der_2048"
" please check the wolfssl/certs_test.h file.\n");
exitApp(ctx);
}
else
{
System_printf("====> tcpclient: loading ca_cert_der_2048 Success \r\n");
}
if (wolfSSL_CTX_use_certificate_buffer(ctx, client_cert_der_2048,sizeof(client_cert_der_2048) / sizeof(char), SSL_FILETYPE_ASN1) != SSL_SUCCESS)
{
System_printf("tcpHandler: Error loading client_cert_der_2048,"
" please check the wolfssl/certs_test.h file.\n");
exitApp(ctx);
}
else
{
System_printf("====> tcpclient: loading client_cert_der_2048 Success \r\n");
}
if (wolfSSL_CTX_use_PrivateKey_buffer(ctx, client_key_der_2048,sizeof(client_key_der_2048) / sizeof(char), SSL_FILETYPE_ASN1)!= SSL_SUCCESS)
{
System_printf("tcpHandler: Error loading client_key_der_2048,"
" please check the wolfssl/certs_test.h file.\n");
exitApp(ctx);
}
else
{
System_printf("====> tcpclient: loading client_key_der_2048 Success \r\n");
}
/* Init the Error_Block */
Error_init(&eb);
do {
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
System_printf("tcpHandler: socket failed\n");
Task_sleep(2000);
continue;
}
memset((char *) &servAddr, 0, sizeof(servAddr));
servAddr.sin_family = AF_INET;
servAddr.sin_port = htons(atoi(usr_s.socket_port)); //TCPPORT;
inet_aton(usr_s.socket_ip, &servAddr.sin_addr); //IP_ADDR
ret = connect(sockfd, (struct sockaddr *) &servAddr, sizeof(servAddr));
if (ret < 0)
{
fdClose((SOCKET) sockfd);
Task_sleep(2000);
continue;
}
} while (ret != 0);
if ((ssl = wolfSSL_new(ctx)) == NULL)
{
System_printf("====> tcpclient: tcpHandler: wolfSSL_new error.\r\n");
exitApp(ctx);
}
else
{
System_printf("====> tcpclient: tcpHandler: wolfSSL_new Success \r\n");
}
wolfSSL_set_fd(ssl, sockfd);
ret = wolfSSL_connect(ssl);
/* Delete "TOP_LINE" and "END_LINE" for debugging. */
System_printf("====> tcpclient: looked for: {%d} \r\n", SSL_SUCCESS);
System_printf("====> tcpclient: return was: {%d} \r\n", ret);
int err;
char err_buffer[80];
err = wolfSSL_get_error(ssl, 0);
System_printf("====> tcpclient: wolfSSL error: {%d} \r\n", err);
System_printf("====> tcpclient: wolfSSL error string: {%s} \r\n", wolfSSL_ERR_error_string(err, err_buffer));
if (ret == SSL_SUCCESS)
{
sockfd = wolfSSL_get_fd(ssl);
/* Get a buffer to receive incoming packets. Use the default heap. */
// buffer = Memory_alloc(NULL, TCPPACKETSIZE, 0, &eb);
buffer = (char *)mmBulkAlloc(TCPPACKETSIZE);
if (buffer == NULL) {
System_printf("tcpWorker: failed to alloc memory\n");
exitApp(ctx);
}
/* Say hello to the server */
while (flag) {
if (wolfSSL_write(ssl, msg, strlen(msg)) != strlen(msg)) {
ret = wolfSSL_get_error(ssl, 0);
System_printf("Write error: %i.\n", ret);
}
while (internal_flag) {
nbytes = wolfSSL_read(ssl, (char *) buffer, TCPPACKETSIZE);
if (nbytes > 0) {
internal_flag = false;
}
}
/* success */
System_printf("Heard: \"%s\".\n", buffer);
wolfSSL_free(ssl);
fdClose((SOCKET) sockfd);
flag = false;
}
/* Free the buffer back to the heap */
// Memory_free(NULL, buffer, TCPPACKETSIZE);
mmBulkFree(buffer);
/*
* Since deleteTerminatedTasks is set in the cfg file,
* the Task will be deleted when the idle task runs.
*/
exitApp(ctx);
}
else
{
wolfSSL_free(ssl);
fdClose((SOCKET) sockfd);
System_printf("wolfSSL_connect failed.\n");
fdCloseSession(TaskSelf());
exitApp(ctx);
}
}