MQTT native TLS

Hi,

Using nRF Connect SDK 2.7.0 on an nRF9160. Using native tls, works fine, i can setup HTTPS connections.

Problems arise when i try to use MQTT with native TLS (with set_native_tls = true in struct mqtt_sec_config). This breaks with "net_sock: get_sock_vtable: (main): Invalid access on sock 4 by thread 0x20021608 (main)".

Using MQTT without native tls (thus not setting set_native_tls = true in struct mqtt_sec_config) does work, if i modify the server side encryption in an appropriate manner. Iow, it would appear that the problem is not in the application code?

Is this a known limitation? Or am i doing something wrong?

Thanks in advance,

Parents
  • Hello,

    Is this a known limitation? Or am i doing something wrong?

    This is not a known limitation. If you show me the code and configs and can try to check if you are doing something wrong. Also, modem trace would be very helpful.

  • trace-2025-06-19T12-25-52.766Z.mtrace

    Hello Hakon,

    Think I'll take you up on that offer to check my project. I'm stuck..

    I've created a small subset of our project, removed everything not related to mqtt, and moved the project to an nrf9160-dk (instead of our custom board). How can i transfer the project to you in a less public way?

    Attached already is a trace. However since we're doing native tls not that much is happening there..

    O, and a bit of console log, the part where i try to setup the mqtt connection. The 'get_sock_vtable' lines are a local addition from me, notice that sock suddenly changes from 3 to 4, which in turn triggers the "invalid access". This seems to happen during the nrf91_socket_create() call.

    [00:00:04.228,302] <inf> modem: LTE connected. Waiting for time update..
    Network up!
    [00:00:04.421,142] <dbg> at_monitor: at_monitor_task: AT notif: %CESQ: 36,1,10,1
    [00:00:04.424,041] <dbg> at_monitor: at_monitor_task: Dispatching to 0x79191
    [00:00:04.428,405] <dbg> modem_info: parse_ip_addresses: Device has 1 IP addresses
    [00:00:04.431,854] <dbg> modem_info: parse_ip_addresses: IP address found: 10.91.0.199
    [00:00:05.087,646] <dbg> net_mqtt_sock_tls: mqtt_client_tls_connect: (main): Created socket 3
    [00:00:05.090,911] <dbg> net_mqtt_sock_tls: mqtt_client_tls_connect: (main): TLS_SEC_TAG_LIST (socket 3)
    [00:00:05.094,268] <dbg> net_sock: get_sock_vtable: (main): (1) sock 3
    [00:00:05.096,984] <dbg> net_sock: get_sock_vtable: (main): (2) sock 3, ctx 0x20021c40
    [00:00:05.100,158] <dbg> net_sock: get_sock_vtable: (main): (1) sock 3
    [00:00:05.102,874] <dbg> net_sock: get_sock_vtable: (main): (2) sock 3, ctx 0x20021c54
    [00:00:05.106,323] <dbg> net_sock: get_sock_vtable: (main): (1) sock 4
    [00:00:05.109,069] <dbg> net_sock: get_sock_vtable: (main): (2) sock 4, ctx 0x0
    [00:00:05.111,968] <dbg> net_sock: get_sock_vtable: (main): Invalid access on sock 4 by thread 0x200212c0 (main)
    [00:00:05.115,570] <dbg> net_sock: get_sock_vtable: (main): (1) sock 3
    [00:00:05.118,316] <dbg> net_sock: get_sock_vtable: (main): (2) sock 3, ctx 0x20021c54
    [00:00:05.121,398] <dbg> net_sock: z_impl_zsock_close: (main): close: ctx=0x20021c54, fd=3
    [00:00:05.124,572] <dbg> mqtt: mqtt_setup_connection: MQTT connect failed (-9)

Reply
  • trace-2025-06-19T12-25-52.766Z.mtrace

    Hello Hakon,

    Think I'll take you up on that offer to check my project. I'm stuck..

    I've created a small subset of our project, removed everything not related to mqtt, and moved the project to an nrf9160-dk (instead of our custom board). How can i transfer the project to you in a less public way?

    Attached already is a trace. However since we're doing native tls not that much is happening there..

    O, and a bit of console log, the part where i try to setup the mqtt connection. The 'get_sock_vtable' lines are a local addition from me, notice that sock suddenly changes from 3 to 4, which in turn triggers the "invalid access". This seems to happen during the nrf91_socket_create() call.

    [00:00:04.228,302] <inf> modem: LTE connected. Waiting for time update..
    Network up!
    [00:00:04.421,142] <dbg> at_monitor: at_monitor_task: AT notif: %CESQ: 36,1,10,1
    [00:00:04.424,041] <dbg> at_monitor: at_monitor_task: Dispatching to 0x79191
    [00:00:04.428,405] <dbg> modem_info: parse_ip_addresses: Device has 1 IP addresses
    [00:00:04.431,854] <dbg> modem_info: parse_ip_addresses: IP address found: 10.91.0.199
    [00:00:05.087,646] <dbg> net_mqtt_sock_tls: mqtt_client_tls_connect: (main): Created socket 3
    [00:00:05.090,911] <dbg> net_mqtt_sock_tls: mqtt_client_tls_connect: (main): TLS_SEC_TAG_LIST (socket 3)
    [00:00:05.094,268] <dbg> net_sock: get_sock_vtable: (main): (1) sock 3
    [00:00:05.096,984] <dbg> net_sock: get_sock_vtable: (main): (2) sock 3, ctx 0x20021c40
    [00:00:05.100,158] <dbg> net_sock: get_sock_vtable: (main): (1) sock 3
    [00:00:05.102,874] <dbg> net_sock: get_sock_vtable: (main): (2) sock 3, ctx 0x20021c54
    [00:00:05.106,323] <dbg> net_sock: get_sock_vtable: (main): (1) sock 4
    [00:00:05.109,069] <dbg> net_sock: get_sock_vtable: (main): (2) sock 4, ctx 0x0
    [00:00:05.111,968] <dbg> net_sock: get_sock_vtable: (main): Invalid access on sock 4 by thread 0x200212c0 (main)
    [00:00:05.115,570] <dbg> net_sock: get_sock_vtable: (main): (1) sock 3
    [00:00:05.118,316] <dbg> net_sock: get_sock_vtable: (main): (2) sock 3, ctx 0x20021c54
    [00:00:05.121,398] <dbg> net_sock: z_impl_zsock_close: (main): close: ctx=0x20021c54, fd=3
    [00:00:05.124,572] <dbg> mqtt: mqtt_setup_connection: MQTT connect failed (-9)

Children
No Data
Related