This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C1294KCPDT: Implementing mbedtls for mqtt/tls using lwip

Part Number: TM4C1294KCPDT
Other Parts Discussed in Thread: MSP432E401Y

Hello Everyone,

I am using Tiva tm4c1294kcpdt NO RTOS. I have tested non secure mqtt client using lwip on mosquitto broker. It works fine.

Now I want to implement secure mqtt i.e. mqtt/tls using mbedtls through lwip raw api functions. I got below link of github for the same & I tried to implement in same way:

"https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/MCUXpresso/FRDM-K64F/FRDM-K64F_lwip_lwip_mqtt_bm/source"

But in this, I got the errors while initialising TLS as below:

1. undefined threading_mutex_init_pthread, threading_mutex_free_pthread, threading_mutex_lock_pthread, threading_mutex_unlock_pthread

2. If I comment this line, then "mbedtls_ctr_drbg_seed" function returns me an error

3. When I try to connect to mosquitto broker using "mqtt_client_connect()" function then it gives me "mqtt_tcp_connect_cb()" connection callback but after that lwip stack calls "mqtt_close()" function with error code 'MQTT_CONNECT_REFUSED_PROTOCOL_VERSION'.

Any help is appreciated.

  • Hi Urvi,

      I think the mbed TLS is SSL library licensee by ARM Ltd. Below is a link to their support website. Their experts will be able to assist you much better than we can as we don't have much knowledge on their software library and implementation. Our knowledge and support is more with the MCU hardware. 

    https://tls.mbed.org/support

  • Hi Charles,

    I contact with mbed tls support team, and tried to implement as per their suggetions. The ssl context setup function 'mbedtls_ssl_setup' calls malloc function from 'ti/ccsv6/tools/compiler/arm_5.1.6/lib/src/memory.c' file.

    In this file:

    /*-----------------------------------------------------------------------*/
    /* SCAN THROUGH FREE LIST FOR PACKET LARGE ENOUGH TO CONTAIN PACKET */
    /*-----------------------------------------------------------------------*/
    while (current && current->packet_size < newsize)
    current = current->size_ptr;

    if (!current)
    {
    _unlock();
    return NULL;
    }

    it returns 'current=null', because of this I am unable to continue with my further tls handshaking process.

    Kindly guide me through this.

  • Hi,

      Not sure what is the real problem. Can you first change the heap size and the also the stack size to a .larger values? For example, change the heap size to 4096 and see if it make some differences?

  • Hi Charles,

    I have already declared heap=stack size=8192 i.e. 8K. But then also the problem was there.

    But I tried to increase heap size to 40k and then my problem get resolved. Thank you.

    Now I have other problem: when I use 'mbedtls_threading_set_alt' function, it gives me following errors:

    threading_mutex_free_pthread, threading_mutex_init_pthread, threading_mutex_lock_pthread , threading_mutex_unlock_pthread unresolved symbols.

    How to resolve this issue?

  • Hi Urvi,

      Glad one of the problems is solved. As I mentioned, you are using some 3rd party software/OS that we are not familiar with. You really need to contact them for support. With that said, if you are getting unresolved symbols, it normally means that the linker didn't find the object of the named symbols (i.e. threading_mutex_free_pthread and etc). These symbols seem coming from some OS related code. You need to compile the source code that contains these symbols and make sure the linker will find the object files that contain these symbols. 

  • Hi Charles,

    threading_mutex_free_pthread functions are not really third party. It is actually under "third_party/mbedtls/ti/port/threading_alt.c" file; where port is belongs to core I guess.

    I have msp432e401y eval kit and i am testing publish_subscribe example on it. Here they are using RTOS with ndk stack along with mbedtls. But in my case I am using non RTOS with lwip along with mbedtls. 

    As I move further with debugging, threading_mutex_free_pthread function calls pthread_mutex_lock function. It further moves to acquireMutex function in 'C:\ti\simplelink_msp432e4_sdk_3_10_00_11\source\ti\posix\tirtos\pthread_mutex.c' file. So instead of msp432 tirtos posix, how can I use tm4c1294kcpdt nortos lwip for this?

    Regards.

  • Hi,

      Below are all the third party code from the latest TivaWare 2.1.4.178 release. There is no mbedtls. I'm not sure where you get it from. Please understand I really can't support something that we don't have in TivaWare release.

    It seems like the mbed TLS is from ARM. If this is the case, would you please contact their support for assistance? https://tls.mbed.org/tech-updates/blog/announcing-lts-branch-mbedtls-2.16

  • Hi,

    TivaWare_C_Series_x doesn't has mbedtls. I am refering it from simplelink_msp432_sdk_x. See below attached image:

    I have already contact mbedtls support team and as per their suggestions I tried to implement the steps and many of bugs get resolved. But at this point I got stuck in this errors that threading_mutex_free_pthread() functions are unresolved.

    For reference you can also go through 'threading_alt.c/.h' and 'entropy_alt.c/.h' files here attached.

    threading_alt.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    /*
    * Threading abstraction layer
    *
    * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
    * SPDX-License-Identifier: Apache-2.0
    *
    * Licensed under the Apache License, Version 2.0 (the "License"); you may
    * not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    * http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the License for the specific language governing permissions and
    * limitations under the License.
    *
    * This file is part of mbed TLS (https://tls.mbed.org)
    */
    #include <mbedtls/threading.h>
    #include "threading_alt.h"
    void threading_mutex_init_pthread( mbedtls_threading_mutex_t *mutex )
    {
    if( mutex == NULL || mutex->is_valid )
    return;
    mutex->is_valid = pthread_mutex_init( &mutex->mutex, NULL ) == 0;
    }
    void threading_mutex_free_pthread( mbedtls_threading_mutex_t *mutex )
    {
    if( mutex == NULL || !mutex->is_valid )
    return;
    (void) pthread_mutex_destroy( &mutex->mutex );
    mutex->is_valid = 0;
    }
    int threading_mutex_lock_pthread( mbedtls_threading_mutex_t *mutex )
    {
    if( mutex == NULL || ! mutex->is_valid )
    return( MBEDTLS_ERR_THREADING_BAD_INPUT_DATA );
    if( pthread_mutex_lock( &mutex->mutex ) != 0 )
    return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
    return( 0 );
    }
    int threading_mutex_unlock_pthread( mbedtls_threading_mutex_t *mutex )
    {
    if( mutex == NULL || ! mutex->is_valid )
    return( MBEDTLS_ERR_THREADING_BAD_INPUT_DATA );
    if( pthread_mutex_unlock( &mutex->mutex ) != 0 )
    return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
    return( 0 );
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    entropy_alt.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    /*
    * Copyright (C) 2017, Texas Instruments Incorporated, All Rights Reserved
    * SPDX-License-Identifier: Apache-2.0
    *
    * Licensed under the Apache License, Version 2.0 (the "License"); you may
    * not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    * http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
    #include <stdlib.h>
    #include <time.h>
    #include <mbedtls/entropy.h>
    #include <entropy_alt.h>
    int entropy_source(void *data, unsigned char *output, size_t len, size_t *olen)
    {
    int i;
    unsigned int seed;
    if (!output || !len || !olen) {
    return (MBEDTLS_ERR_ENTROPY_SOURCE_FAILED);
    }
    if (data != NULL) {
    seed = *(int *)data ^ time(NULL);
    }
    else {
    seed = time(NULL);
    }
    srand(seed);
    for (i = 0; i < len; i++) {
    output[i] = rand() % 256;
    }
    *olen = len;
    return (0);
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    MY MAIN PROBLEM IS I WANT TO  IMPLEMENT SECURE MQTT CLIENT ON TIVA TM4C1294KCPDT USING LWIP+MBEDTLS.

    As for now I tried to implement mbedtls steps and now I am stuck where actually low level core relevant implemetation is there. For MSP IC they have given posix functions which are relevant to msp core; but I want to implement it on tm4c.

    Any one having knowledge on both msp432_sdk and tivaware kindly help me through this....

    Regards.

  • Hi Urvi,

      Now I understand you got from the simplelink for msp432. Please note that simplelink is a completely different platform for software development compared to the TivaWare. As a matter of fact, the msp432 and Tiva are two different product lines. I have no knowledge of simplelink SDK at all as Tiva does not support simplelink. We can't support you if you are trying to use simplelink software on  Tiva devices. Have you post your question to the MSP forum at https://e2e.ti.com/support/microcontrollers/msp430/f/166. I hope their experts can assist your question related to the Simplelink SDK.