From cc6fb0908f903fe11709590e91c6ca9384a50156 Mon Sep 17 00:00:00 2001 From: Pehr Nord Date: Mon, 23 May 2022 15:25:01 +0200 Subject: [PATCH] Add function to reset lwm2m-context of a client - No existing API for "closing" a lwm2m connection if for example the underlying connection is terminated. - lwm2m_deregister does not fit since it assumes the underlying connection is active. Signed-off-by: Pehr Nord --- core/liblwm2m.c | 10 ++++++++++ include/liblwm2m.h | 1 + 2 files changed, 11 insertions(+) diff --git a/core/liblwm2m.c b/core/liblwm2m.c index 8a2d69ec1..c93f3e3f6 100644 --- a/core/liblwm2m.c +++ b/core/liblwm2m.c @@ -332,6 +332,16 @@ int lwm2m_configure(lwm2m_context_t * contextP, return COAP_NO_ERROR; } +void lwm2m_reset(lwm2m_context_t *contextP) { + LOG("Entering"); + contextP->state = STATE_INITIAL; + prv_deleteServerList(contextP); + prv_deleteBootstrapServerList(contextP); + prv_deleteObservedList(contextP); + + prv_deleteTransactionList(contextP); +} + int lwm2m_add_object(lwm2m_context_t * contextP, lwm2m_object_t * objectP) { diff --git a/include/liblwm2m.h b/include/liblwm2m.h index 9995d69cb..a8253f37e 100644 --- a/include/liblwm2m.h +++ b/include/liblwm2m.h @@ -824,6 +824,7 @@ void lwm2m_handle_packet(lwm2m_context_t *contextP, uint8_t *buffer, size_t leng // LWM2M Security Object (ID 0) must be present with either a bootstrap server or a LWM2M server and // its matching LWM2M Server Object (ID 1) instance int lwm2m_configure(lwm2m_context_t * contextP, const char * endpointName, const char * msisdn, const char * altPath, uint16_t numObject, lwm2m_object_t * objectList[]); +void lwm2m_reset(lwm2m_context_t *contextP); int lwm2m_add_object(lwm2m_context_t * contextP, lwm2m_object_t * objectP); int lwm2m_remove_object(lwm2m_context_t * contextP, uint16_t id);