1

(4 replies, posted in wolfMQTT)

Hi embhorn,

i'm using the freertos library added by STM32CubeMx, haven't seen any pthread related stuff there. So have to implement them. I guess THREAD_CREATE & THREAD_EXIT shouldn't be a problem, but what about THREAD_JOIN. Could i implement it by using following

vTaskGetInfo( tcpclientHandle, &xTaskDetails,eInvalid );
if(xTaskDetails.eCurrentState == eDeleted) {...}

Just wait until thread has exited.

Thanks in advance

2

(4 replies, posted in wolfMQTT)

Hi,
I`m tried the mqtt simple and it work flawlessly. Now i like to try the multithreading approach in the examples folder for a freertos setup.
When unlocking this feature got those APIs.

    /* Posix (Linux/Mac) */
    #include <pthread.h>
    #include <sched.h>
    #include <errno.h>
    typedef pthread_t THREAD_T;
    #define THREAD_CREATE(h, f, c) ({ int ret = pthread_create(h, NULL, f, c); if (ret) { errno = ret; } ret; })
    #define THREAD_JOIN(h, c)      ({ int ret, x; for(x=0;x<c;x++) { ret = pthread_join(h[x], NULL); if (ret) { errno = ret; break; }} ret; })
    #define THREAD_EXIT(e)         pthread_exit((void*)e)

but there for Linux. Do i have to overwrite those and place them somewhere? For instance Semaphores are defined and unlocked in "mqtt_client.c".

Thanks in advance

3

(3 replies, posted in wolfSSL)

Hi Kareem,

i'm already connected this is past me and i have also published a greeting to the broker. But after that my paho mqtt library needs to invoke repeatedly a function which handles receiving and also the keepalive, but here it fails. I'm using also my own socket not the one from LWIP. And those are implemented together with timeouts, not using a select on that. So it will stay in amount of time and come back. Well here i would expect 0 as a return, this would be considered a timeout, but unfortunately it comes back with -1. Checking the error returns 0. This should be fine i think so. But question is now how to exit the library correctly. I tried change the return value to WOLFSSL_CBIO_ERR_TIMEOUT, but gave me some other failure -308.

BTW, not able to upload any file.

Thanks,
MO

4

(3 replies, posted in wolfSSL)

Hi, need help can't figure out why this happens. I like to use my sockets together with SO_RCVTIMEO. And library should handle this, but don't know if it does. Have added some code which i think causes this to happen.

int pahoclient_start( const char *ip, int port )
{
    /* Define a structure to hold the WolfSSL context. */
    WOLFSSL_CTX* ctx;
    WOLFSSL* ssl = NULL;
    int fd;

    /* Low level socket apis  */
    NetInit(&net);
    if(NetConnect(&fd, ip , port, 10000) < 0)
        return FAILURE;

    net.fd = fd;

    /* enable debugging */
#if defined(DEBUG_WOLFSSL)
    wolfSSL_Debugging_ON();
#endif

    /* Setup the WolfSSL library */
    wolfSSL_Init();

    /* Create and initialize WOLFSSL_CTX */
    if ((ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())) == NULL) {
        fprintf(stderr, "ERROR: failed to create WOLFSSL_CTX\n");
        goto exit;
    }

    /* Load client certificates into WOLFSSL_CTX */
    if (wolfSSL_CTX_load_verify_buffer(ctx, client_cert_home,client_cert_home_length, SSL_FILETYPE_PEM) != SSL_SUCCESS) {
        fprintf(stderr, "ERROR: failed to load %s, please check the file.\n", client_cert);
        goto exit;
    }

    /* define client callbacks */
    wolfSSL_CTX_SetIOSend(ctx, TlsSocketSend);
    wolfSSL_CTX_SetIORecv(ctx, TlsSocketReceive);

    /* Create a WOLFSSL object */
    if ((ssl = wolfSSL_new(ctx)) == NULL) {
        fprintf(stderr, "ERROR: failed to create WOLFSSL object\n");
        goto exit;
    }

    /* Attach wolfSSL to the socket */
    wolfSSL_set_fd(ssl, fd);

    wolfSSL_SetIOReadCtx(ssl, (void *)&net);
    wolfSSL_SetIOWriteCtx(ssl, (void *)&net);

    /* Connect to wolfSSL on the server side */
    if (wolfSSL_connect(ssl) != SSL_SUCCESS) {
        fprintf(stderr, "ERROR: failed to connect to wolfSSL\n");
        goto exit;
    }

    /* mqtt lower level apis */
    mqtt.mqttread = mqtt_read;
    mqtt.mqttwrite = mqtt_write;
    mqtt.disconnect = mqtt_disconnect;

    wolfssl = ssl;

    MQTTClientInit(&client, &mqtt, 10000, sendbuf, sizeof(sendbuf), readbuf, sizeof(readbuf));
    MQTTPacket_connectData    options = MQTTPacket_connectData_initializer;


    options.cleansession = 1;
    options.clientID.cstring = "ClientID";
    options.keepAliveInterval    = 6000;
    options.willFlag = 0;
    options.MQTTVersion = 3;
    options.username.cstring = "abcdef";
    options.password.cstring = "12345678";

    if(MQTTConnect(&client, &options) <0 )
        goto exit;

    if(MQTTSubscribe(&client, "huhu" , QOS1, MqttMessageArrived) < 0)
        goto exit;


    return MQTTSUCCESS;

exit:
    wolfSSL_free( ssl );
    wolfSSL_CTX_free( ctx );
    wolfSSL_Cleanup();
    NetDisconnect( &net.fd );
    return FAILURE;
}

int pahoclient_run(void)
{
    int rc = MQTTSUCCESS;

    if(MQTTIsConnected(&client)) {
        rc = MQTTYield(&client, 100);
    }

    return rc;
}

int NetRead( int* fd, char *Buf, int len, int timeout_ms)
{
    int rc;
    struct timeval tv;
    int so_error = 0;
    int index;

    /* check before entering */
    if(*fd < 0 || Buf == NULL || len <= 0)
        return -1;

    /* Set timeouts for socket */
    setup_timeout(&tv, timeout_ms);
    rc = setsockopt( *fd, SOL_SOCKET, SO_RCVTIMEO, (void*)&tv, sizeof(tv));
    LWIP_ASSERT("rcvtimeo sockopt", rc == 0);

    index = 0;

    /* Try reading amount of data */
    while( index < len ) {
        rc = read( *fd, &Buf[index], len - index );
        if(rc < 0) {
            /* Get error */
            socklen_t len = sizeof(so_error);
            getsockopt(*fd, SOL_SOCKET, SO_ERROR, &so_error, &len);
            if (so_error == 0) {
                LWIP_ASSERT("socketerror", so_error == 0);
                rc = so_error; /* return error */
                index = len;
                break;
            }
        }
        else {
            index += rc;
        }
    };

    LWIP_ASSERT("index == len", index == (int)len);

    return rc;
}

static int TlsSocketReceive(WOLFSSL* ssl, char *buf, int sz, void *ptr)
{
    int rc;
    Net *net = (Net*)ptr;
    (void)ssl; /* Not used */
    rc = net->read(&net->fd, (char*)buf, sz, 100);
    if (rc == 0) {
        rc = WOLFSSL_CBIO_ERR_WANT_READ; <--- this is the place causing the error
    }
    else if (rc < 0) {
        rc = WOLFSSL_CBIO_ERR_GENERAL;
    }
    return rc;
}

What is the correct way of using wolfssl together with lwip library and timeouts?
Thanks in advance

5

(3 replies, posted in wolfSSL)

That was fast.

I tried it by defining WOLFSSL_LWIP_NATIVE, but i got the next problem.

Now

EMS extension to write
Assertion "tcp_write: invalid pcb" failed at line 414 in ../Middlewares/Third_Party/LwIP/src/core/tcp_out.c
wolfSSL Leaving SendClientHello, return -308

pcb is NULL

6

(3 replies, posted in wolfSSL)

Hi i am struggling with some configurations issues.

I am using the STM32CcubeMx and like to have an Freertos, lwip and wolfssl as my setup. I basically left all in it's default. Tried a client connection but failed. It's hard to figure out the correct setting in multiple header files and here to set callbacks.

My debug error

Your IO Send callback is null, please set
wolfSSL Leaving SendClientHello, return -308
wolfSSL error occurred, error = -308
wolfSSL Leaving wolfSSL_negotiate, return -1
wolfSSL Leaving wolfSSL_write, return -1

7

(9 replies, posted in wolfSSL)

Hi there,

i like to use the wolfssl lib for encyrption on my stm32f4 i aalso want to use the raw lwip from the stm32cube.
I was able to set it up as described in the "Lwip native #599" post. I got it to work but i get error debug prints.

wolfSSL Entering TLSv1_2_client_method_ex
wolfSSL Entering wolfSSL_CTX_new_ex
wolfSSL Entering wolfSSL_Init
wolfSSL Entering wolfCrypt_Init
wolfSSL Entering wolfSSL_CertManagerNew
wolfSSL Leaving WOLFSSL_CTX_new, return 0
wolfSSL Entering wolfSSL_CTX_set_verify
wolfSSL Entering SSL_new
wolfSSL Leaving SSL_new, return 0
wolfSSL Entering SSL_connect()
wolfSSL Entering SendClientHello
Adding signature algorithms extension
growing output buffer
Signature Algorithms extension to write
Point Formats extension to write
Supported Groups extension to write
Encrypt-Then-Mac extension to write
EMS extension to write
Your IO Send callback is null, please set
wolfSSL Leaving SendClientHello, return -308
wolfSSL error occurred, error = -308
wolfSSL Entering SSL_get_error
wolfSSL Leaving SSL_get_error, return -308
SSL_connect failed
wolfSSL Entering SSL_write()
handshake not complete, trying to finish
wolfSSL Entering wolfSSL_negotiate
wolfSSL Entering SSL_connect()
Your IO Send callback is null, please set
wolfSSL error occurred, error = -308
wolfSSL Leaving wolfSSL_negotiate, return -1
wolfSSL Leaving SSL_write(), return -1
SSL_write failed
wolfSSL Entering wolfSSL_read()


What does that mean "Your IO Send callback is null, please set" i thought this was set up in "client-nb.c" with
"wolfSSL_SetIO_LwIP(ssl, sockfd, NULL, NULL, NULL);" api.
Although it is a little bit odd because the cb for recv and send are both NULL.
Do i have to place my own tcp recv and send function?

Thanks in advance