net: lwm2m: remove special handling for message id 0

Change so that the caller of lwm2m_init_message is
responsible for generating a message id and remove message id generation
from lwm2m_init_message. Prevents generating a new id when the caller's
intent is to init a message with id 0.

Fixes #28283

Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
This commit is contained in:
Pascal Brogle 2020-09-10 16:23:48 +02:00 committed by Maureen Helm
commit 32f053403f
4 changed files with 6 additions and 10 deletions

View file

@ -948,8 +948,7 @@ int lwm2m_init_message(struct lwm2m_message *msg)
} }
r = coap_packet_init(&msg->cpkt, msg->msg_data, sizeof(msg->msg_data), r = coap_packet_init(&msg->cpkt, msg->msg_data, sizeof(msg->msg_data),
1, msg->type, tokenlen, token, msg->code, 1, msg->type, tokenlen, token, msg->code, msg->mid);
(msg->mid == LWM2M_MSG_ID_GENERATE_NEW ? coap_next_id() : msg->mid));
if (r < 0) { if (r < 0) {
LOG_ERR("coap packet init error (err:%d)", r); LOG_ERR("coap packet init error (err:%d)", r);
goto cleanup; goto cleanup;
@ -3973,7 +3972,7 @@ static int generate_notify_message(struct observe_node *obs,
msg->type = COAP_TYPE_CON; msg->type = COAP_TYPE_CON;
msg->code = COAP_RESPONSE_CODE_CONTENT; msg->code = COAP_RESPONSE_CODE_CONTENT;
msg->mid = LWM2M_MSG_ID_GENERATE_NEW; msg->mid = coap_next_id();
msg->token = obs->token; msg->token = obs->token;
msg->tkl = obs->tkl; msg->tkl = obs->tkl;
msg->reply_cb = notify_message_reply_cb; msg->reply_cb = notify_message_reply_cb;

View file

@ -41,9 +41,6 @@
/* Use this value to skip token generation */ /* Use this value to skip token generation */
#define LWM2M_MSG_TOKEN_LEN_SKIP 0xFF #define LWM2M_MSG_TOKEN_LEN_SKIP 0xFF
/* Use this value to generate a new message id */
#define LWM2M_MSG_ID_GENERATE_NEW 0U
/* length of time in milliseconds to wait for buffer allocations */ /* length of time in milliseconds to wait for buffer allocations */
#define BUF_ALLOC_TIMEOUT K_SECONDS(1) #define BUF_ALLOC_TIMEOUT K_SECONDS(1)

View file

@ -84,7 +84,7 @@ static int transfer_request(struct coap_block_context *ctx,
msg->type = COAP_TYPE_CON; msg->type = COAP_TYPE_CON;
msg->code = COAP_METHOD_GET; msg->code = COAP_METHOD_GET;
msg->mid = LWM2M_MSG_ID_GENERATE_NEW; msg->mid = coap_next_id();
msg->token = token; msg->token = token;
msg->tkl = tkl; msg->tkl = tkl;
msg->reply_cb = reply_cb; msg->reply_cb = reply_cb;

View file

@ -549,7 +549,7 @@ static int sm_do_bootstrap_reg(void)
msg->type = COAP_TYPE_CON; msg->type = COAP_TYPE_CON;
msg->code = COAP_METHOD_POST; msg->code = COAP_METHOD_POST;
msg->mid = LWM2M_MSG_ID_GENERATE_NEW; msg->mid = coap_next_id();
msg->reply_cb = do_bootstrap_reply_cb; msg->reply_cb = do_bootstrap_reply_cb;
msg->message_timeout_cb = do_bootstrap_reg_timeout_cb; msg->message_timeout_cb = do_bootstrap_reg_timeout_cb;
@ -629,7 +629,7 @@ static int sm_send_registration(bool send_obj_support_data,
msg->type = COAP_TYPE_CON; msg->type = COAP_TYPE_CON;
msg->code = COAP_METHOD_POST; msg->code = COAP_METHOD_POST;
msg->mid = LWM2M_MSG_ID_GENERATE_NEW; msg->mid = coap_next_id();
msg->reply_cb = reply_cb; msg->reply_cb = reply_cb;
msg->message_timeout_cb = timeout_cb; msg->message_timeout_cb = timeout_cb;
@ -821,7 +821,7 @@ static int sm_do_deregister(void)
msg->type = COAP_TYPE_CON; msg->type = COAP_TYPE_CON;
msg->code = COAP_METHOD_DELETE; msg->code = COAP_METHOD_DELETE;
msg->mid = LWM2M_MSG_ID_GENERATE_NEW; msg->mid = coap_next_id();
msg->reply_cb = do_deregister_reply_cb; msg->reply_cb = do_deregister_reply_cb;
msg->message_timeout_cb = do_deregister_timeout_cb; msg->message_timeout_cb = do_deregister_timeout_cb;