Topic: wolfSSL_new error -173

Hello,
I just compiled the wolfSSL library as static for cortex m0 with arm gcc
I folowed the example that you have, but i keep getting -173 on wolfSSL_new

Here is how i compiled the library:

./configure --host=arm-none-eabi \
    CC="arm-none-eabi-gcc" \
    CFLAGS="-ffreestanding -mcpu=cortex-m0 -mthumb -Os -DWOLFSSL_USER_SETTINGS -DNO_STDIO_FILESYSTEM -Wno-unused-parameter" \
    LDFLAGS="-nostdlib" \
    --prefix=/c/wolfssl-arm-tls \
    --enable-static \
    --disable-shared \
    --enable-singlethreaded \
    --disable-filesystem \
    --enable-aesgcm \
    --disable-asm \
    --disable-examples \
    --disable-benchmark \
    --disable-crypttests

And here is my user_settings.h

#ifndef USER_SETTINGS_H
#define USER_SETTINGS_H

/* Embedded setup */
#define NO_POSIX_IO
#define NO_MAIN_DRIVER
#define WOLFSSL_NO_STDIO
#define WOLFSSL_SMALL_STACK
#define WOLFSSL_NO_SOCK
#define NO_WRITEV      /* Prevent inclusion of <sys/uio.h> */
#define WOLFSSL_USER_IO

#endif /* USER_SETTINGS_H */

and this is my code:

#include "options.h"
#include "ssl.h"
#include "inet.h"
#define MAXSZ              1024
int CbIORecv(WOLFSSL *ssl, char *buf, int sz, void *ctx) {
    u8 socket_id = 1; // Retrieve socket ID from context
    u16 len = (u16)sz;       // Size requested by WolfSSL
    u32 result;

    // Call inetSocketRead, which updates len with actual data read
    result = inetSocketRead(socket_id, buf, &len);

    if (result == 0) { // Success: data was read
        DEBPOINT();
        return (int)len; // Return number of bytes read
    } else if (result == errNoData) { // No data available
        DEBPOINT();
        return WOLFSSL_CBIO_ERR_WANT_READ; // Indicate non-blocking read needs retry
    } else {
        DEBPOINT();
        return WOLFSSL_CBIO_ERR_GENERAL; // Other errors
    }
}
int CbIOSend(WOLFSSL *ssl, char *buf, int sz, void *ctx) {
    u8 socket_id = 1; // Retrieve socket ID from context
    u32 result;

    // Call inetSocketWrite to send data
    result = inetSocketWrite(socket_id, buf, (u16)sz);

    if (result == 0) { // Success: data was sent
        DEBPOINT();
        return sz; // Return number of bytes sent
    } else {
        DEBPOINT();
        return WOLFSSL_CBIO_ERR_GENERAL; // Handle error
    }
}
static int tls_client(void)
{
    char msg[] = "Hello WolfSSL!\r\n";
    char reply[MAXSZ];
    int ret, msgSz, error;
    WOLFSSL* ssl = NULL;
    WOLFSSL_CTX* ctx = NULL;

    WOLFSSL_METHOD* method = wolfTLSv1_2_client_method();
    if (method == NULL) {
        debprintf("ERRO: wolfTLSv1_2_client_method failed\n");
        return -1;
    }
    ctx = wolfSSL_CTX_new(method);
    wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_NONE, NULL);
    if ( ctx == NULL ) 
    {
        debprintf("ERRO: WOLFSSL_CTX\n");
        return -1;
    }
    wolfSSL_CTX_SetIORecv(ctx, CbIORecv);
    wolfSSL_CTX_SetIOSend(ctx, CbIOSend);
    ssl = wolfSSL_new(ctx);
    if ( ssl == NULL ) 
    {
        int error = wolfSSL_get_error(ssl, 0);
        debprintf("ERRO: wolfSSL_new: %d\n", error);
        wolfSSL_CTX_free(ctx);
        wolfSSL_Cleanup();
        return -1;
    }

    /* non blocking accept and connect */
    ret = WOLFSSL_FAILURE;

    while (ret != WOLFSSL_SUCCESS) {
        /* client connect */
        ret = wolfSSL_connect(ssl);
        error = wolfSSL_get_error(ssl, 0);
        if (ret != WOLFSSL_SUCCESS) {
            if (error != WOLFSSL_ERROR_WANT_READ && error != WOLFSSL_ERROR_WANT_WRITE) {
                /* Fail */
                debprintf("wolfSSL connect failed with return code %d\n", error);
                goto fail;
            }
        }
        /* Success */
    }

    /* read and write */
    while (1) {
        /* client send/read */
        msgSz = sizeof(msg);
        ret   = wolfSSL_write(ssl, msg, msgSz);
        error = wolfSSL_get_error(ssl, 0);
        if (ret != msgSz) {
            if (error != WOLFSSL_ERROR_WANT_READ && error != WOLFSSL_ERROR_WANT_WRITE) {
                /* Write failed */
                goto fail;
            }
        }
        /* Write succeeded */
        break;
    }

    while (1) {
        ret = wolfSSL_read(ssl, reply, sizeof(reply) - 1);
        error = wolfSSL_get_error(ssl, 0);
        if (ret < 0) {
            if (error != WOLFSSL_ERROR_WANT_READ && error != WOLFSSL_ERROR_WANT_WRITE) {
                /* Can put print here, the server enters a loop waiting to read
                 * a confirmation message at this point */
                // printf("client read failed\n");
                goto fail;
            }
            continue;
        }
        else {
            /* Can put print here, the server enters a loop waiting to read
             * a confirmation message at this point */
            reply[ret] = '\0';
            debprintf("Client Received Reply: %s\n", reply);
            break;
        }

    }

    return 0;

fail:
    wolfSSL_shutdown(ssl);
    wolfSSL_free(ssl);
    wolfSSL_CTX_free(ctx);

    return -1;
}


void wolfSSLTest(){
    int ret;
    
    // Open TCP socket
    debprintf("Opening TCP socket on WIFI, socket ID 1, to 192.168.9.66:4433, timeout 10s\n");
    ret = inetSocketOpenTCP(INET_DEVICE_WIFI, 1, "192.168.9.66", 4433, 10);
    wolfSSL_Init();
    ret = tls_client();
    wolfSSL_Cleanup();
    ret = inetSocketClose(1);
    if (ret != 0) {
        debprintf("ERROR: inetSocketClose failed with error code %d\n", ret);
        return;
    }
    debprintf("Socket closed successfully\n");

    return;
}

Share

Re: wolfSSL_new error -173

Hello krcenov,

Welcome to the wolfSSL Forums!

I see you are specifying `-DWOLFSSL_USER_SETTINGS` in the CFLAGS. But you are also adding settings using ./configure. These could be conflicting. We recommend using either the `user_settings.h` header, or `./configure` and generating the options.h header.

Are you including the settings header before any other wolfSSL includes?

Check out our examples repository:
https://github.com/wolfSSL/wolfssl-examples

Specifically:
https://github.com/wolfSSL/wolfssl-exam … callback.c

Can you tell us a bit about yourself and the project you are working on for our support records? Feel free to send an email to support@wolfssl.com for a more private correspondence.

Thanks,
Eric - wolfSSL Support