net: lwm2m: init pendings and replies on lwm2m_engine_start

On OT network with poor coverage, very often request/observe packets
doesn't get it's ACK and consumes from pendings/replies/message stacks.
In such cases when LWM2M engine tries to recover by resetting its state,
it fails because of lack of free messages.

Signed-off-by: Kiril Petrov <retfie@gmail.com>
This commit is contained in:
Kiril Petrov 2020-02-23 20:04:10 +02:00 committed by Jukka Rissanen
commit ea072341d5

View file

@ -4005,6 +4005,8 @@ int lwm2m_engine_context_close(struct lwm2m_ctx *client_ctx)
struct observe_node *obs, *tmp;
sys_snode_t *prev_node = NULL;
int sock_fd = client_ctx->sock_fd;
struct lwm2m_message *msg;
size_t i;
/* Cancel pending retransmit work */
k_delayed_work_cancel(&client_ctx->retransmit_work);
@ -4021,6 +4023,16 @@ int lwm2m_engine_context_close(struct lwm2m_ctx *client_ctx)
}
}
for (i = 0, msg = messages; i < CONFIG_LWM2M_ENGINE_MAX_MESSAGES;
i++, msg++) {
memset(msg, 0, sizeof(struct lwm2m_message));
}
coap_pendings_clear(client_ctx->pendings,
CONFIG_LWM2M_ENGINE_MAX_PENDING);
coap_replies_clear(client_ctx->replies,
CONFIG_LWM2M_ENGINE_MAX_REPLIES);
lwm2m_socket_del(client_ctx);
client_ctx->sock_fd = -1;
if (sock_fd >= 0) {