net: lwm2m: use defines for message id and token generation
message id 0 and token 0 have special semantics in the lwm2m engine, they are used to request generation of new id, mark them as such. Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
This commit is contained in:
parent
121937e071
commit
18a51a0bf6
4 changed files with 13 additions and 7 deletions
|
@ -939,7 +939,7 @@ int lwm2m_init_message(struct lwm2m_message *msg)
|
|||
* msg->tkl == 0 is for a new TOKEN
|
||||
* msg->tkl == LWM2M_MSG_TOKEN_LEN_SKIP means dont set
|
||||
*/
|
||||
if (msg->tkl == 0U) {
|
||||
if (msg->tkl == LWM2M_MSG_TOKEN_GENERATE_NEW) {
|
||||
tokenlen = 0U;
|
||||
token = coap_next_token();
|
||||
} else if (msg->token && msg->tkl != LWM2M_MSG_TOKEN_LEN_SKIP) {
|
||||
|
@ -949,7 +949,7 @@ int lwm2m_init_message(struct lwm2m_message *msg)
|
|||
|
||||
r = coap_packet_init(&msg->cpkt, msg->msg_data, sizeof(msg->msg_data),
|
||||
1, msg->type, tokenlen, token, msg->code,
|
||||
(msg->mid > 0 ? msg->mid : coap_next_id()));
|
||||
(msg->mid == LWM2M_MSG_ID_GENERATE_NEW ? coap_next_id() : msg->mid));
|
||||
if (r < 0) {
|
||||
LOG_ERR("coap packet init error (err:%d)", r);
|
||||
goto cleanup;
|
||||
|
@ -3973,7 +3973,7 @@ static int generate_notify_message(struct observe_node *obs,
|
|||
|
||||
msg->type = COAP_TYPE_CON;
|
||||
msg->code = COAP_RESPONSE_CODE_CONTENT;
|
||||
msg->mid = 0U;
|
||||
msg->mid = LWM2M_MSG_ID_GENERATE_NEW;
|
||||
msg->token = obs->token;
|
||||
msg->tkl = obs->tkl;
|
||||
msg->reply_cb = notify_message_reply_cb;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue