Skip to content

Commit

Permalink
tests: lwm2m: Enable DTLS CID for interoperability tests
Browse files Browse the repository at this point in the history
Leshan Demo server seem to support it so it makes sense to
use it.

Signed-off-by: Seppo Takalo <[email protected]>
  • Loading branch information
SeppoTakalo authored and carlescufi committed Nov 7, 2023
1 parent 0a10418 commit 1506a43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/net/lib/lwm2m/interop/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=40
CONFIG_LWM2M_QUEUE_MODE_ENABLED=y
CONFIG_LWM2M_QUEUE_MODE_UPTIME=20
CONFIG_LWM2M_UPDATE_PERIOD=30
CONFIG_LWM2M_RD_CLIENT_STOP_POLLING_AT_IDLE=y

# LwM2M configuration as OMA-ETS-LightweightM2M_INT-V1_1-20190912-D Configuration 3
CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=30
Expand Down Expand Up @@ -75,6 +76,7 @@ CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
# LwM2M engine should not use more than one on any given time.
CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS=1
CONFIG_NET_SOCKETS_ENABLE_DTLS=y
CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID=y

# Assume that IPv6 minimum MTU is accepted
# MTU - IPv6 header - UDP header - DTLS header - CoAP header room
Expand Down
20 changes: 20 additions & 0 deletions tests/net/lib/lwm2m/interop/src/lwm2m-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/net/lwm2m.h>
#include <zephyr/net/socket.h>

#define APP_BANNER "Run LWM2M client"

Expand Down Expand Up @@ -58,6 +59,24 @@ static int device_reboot_cb(uint16_t obj_inst_id,
return 0;
}

int set_socketoptions(struct lwm2m_ctx *ctx)
{
if (IS_ENABLED(CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID) && ctx->use_dtls) {
int ret;

/* Enable CID */
int cid = TLS_DTLS_CID_ENABLED;

ret = zsock_setsockopt(ctx->sock_fd, SOL_TLS, TLS_DTLS_CID, &cid,
sizeof(cid));
if (ret) {
ret = -errno;
LOG_ERR("Failed to enable TLS_DTLS_CID: %d", ret);
}
}
return lwm2m_set_default_sockopt(ctx);
}

static int lwm2m_setup(void)
{
/* setup DEVICE object */
Expand Down Expand Up @@ -201,6 +220,7 @@ int main(void)
}

client.tls_tag = 1;
client.set_socketoptions = set_socketoptions;

lwm2m_rd_client_start(&client, CONFIG_BOARD, 0, rd_client_event, observe_cb);
lwm2m_rd_client_stop(&client, rd_client_event, false);
Expand Down

0 comments on commit 1506a43

Please sign in to comment.