net: lwm2m: engine: add flag for separate response

Separate response can happen when handling block transfer for firmware
updates, and to avoid duplicating the lwm2m_udp_receive function, create
and additional flag to allow handling CoAP separate response messages.
This is required to avoid removing the reply callback, since a new
message (with a valid token) will be received later from the server.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
This commit is contained in:
Ricardo Salveti 2017-07-28 19:21:58 -03:00 committed by Jukka Rissanen
commit 3896930be6
3 changed files with 21 additions and 4 deletions

View file

@ -2154,6 +2154,7 @@ int lwm2m_udp_sendto(struct net_pkt *pkt, const struct sockaddr *dst_addr)
void lwm2m_udp_receive(struct net_context *ctx, struct net_pkt *pkt,
struct zoap_pending *zpendings, int num_zpendings,
struct zoap_reply *zreplies, int num_zreplies,
bool handle_separate_response,
int (*udp_request_handler)(struct zoap_packet *,
struct zoap_packet *,
struct sockaddr *))
@ -2256,9 +2257,24 @@ void lwm2m_udp_receive(struct net_context *ctx, struct net_pkt *pkt,
SYS_LOG_ERR("No handler for response");
}
} else {
SYS_LOG_DBG("reply handled reply:%p", reply);
/*
* Separate response is composed of 2 messages, empty ACK with
* no token and an additional message with a matching token id
* (based on the token used by the CON request).
*
* Since the ACK received by the notify CON messages are also
* empty with no token (consequence of always using the same
* token id for all notifications), we have to use an
* additional flag to decide when to clear the reply callback.
*/
if (handle_separate_response && !tkl &&
zoap_header_get_type(&response) == ZOAP_TYPE_ACK) {
SYS_LOG_DBG("separated response, not removing reply");
} else {
SYS_LOG_DBG("reply %p handled and removed", reply);
zoap_reply_clear(reply);
}
}
cleanup:
if (pkt) {
@ -2270,7 +2286,7 @@ static void udp_receive(struct net_context *ctx, struct net_pkt *pkt,
int status, void *user_data)
{
lwm2m_udp_receive(ctx, pkt, pendings, NUM_PENDINGS,
replies, NUM_REPLIES, handle_request);
replies, NUM_REPLIES, false, handle_request);
}
static void retransmit_request(struct k_work *work)

View file

@ -54,6 +54,7 @@ int lwm2m_udp_sendto(struct net_pkt *pkt, const struct sockaddr *dst_addr);
void lwm2m_udp_receive(struct net_context *ctx, struct net_pkt *pkt,
struct zoap_pending *zpendings, int num_zpendings,
struct zoap_reply *zreplies, int num_zreplies,
bool handle_separate_response,
int (*udp_request_handler)(struct zoap_packet *request,
struct zoap_packet *response,
struct sockaddr *from_addr));

View file

@ -47,7 +47,7 @@ firmware_udp_receive(struct net_context *ctx, struct net_pkt *pkt, int status,
void *user_data)
{
lwm2m_udp_receive(ctx, pkt, pendings, NUM_PENDINGS,
replies, NUM_REPLIES, NULL);
replies, NUM_REPLIES, true, NULL);
}
static void retransmit_request(struct k_work *work)