net: lwm2m: support client-initiated De-register
Add new RD Client API of lwm2m_rd_client_stop() for this Fix issues of de-register and event reporting in RD Client Signed-off-by: Jun Qing Zou <jun.qing.zou@nordicsemi.no>
This commit is contained in:
parent
a75b0014fb
commit
ca783d72a6
2 changed files with 34 additions and 4 deletions
|
@ -868,6 +868,21 @@ typedef void (*lwm2m_ctx_event_cb_t)(struct lwm2m_ctx *ctx,
|
|||
void lwm2m_rd_client_start(struct lwm2m_ctx *client_ctx, const char *ep_name,
|
||||
lwm2m_ctx_event_cb_t event_cb);
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_NET_LWM2M_H_ */
|
||||
/**
|
||||
* @brief Stop the LwM2M RD (De-register) Client
|
||||
*
|
||||
* The RD client sits just above the LwM2M engine and performs the necessary
|
||||
* actions to implement the "Registration interface".
|
||||
* For more information see Section 5.3 "Client Registration Interface" of the
|
||||
* LwM2M Technical Specification.
|
||||
*
|
||||
* @param[in] client_ctx LwM2M context
|
||||
* @param[in] event_cb Client event callback function
|
||||
*
|
||||
* @return 0 for success or negative in case of error.
|
||||
*/
|
||||
void lwm2m_rd_client_stop(struct lwm2m_ctx *client_ctx,
|
||||
lwm2m_ctx_event_cb_t event_cb);
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_NET_LWM2M_H_ */
|
||||
/**@} */
|
||||
|
|
|
@ -130,7 +130,7 @@ static void set_sm_state(u8_t sm_state)
|
|||
} else if ((sm_state == ENGINE_INIT ||
|
||||
sm_state == ENGINE_DEREGISTERED) &&
|
||||
(client.engine_state >= ENGINE_DO_REGISTRATION &&
|
||||
client.engine_state < ENGINE_DEREGISTER)) {
|
||||
client.engine_state <= ENGINE_DEREGISTER_SENT)) {
|
||||
event = LWM2M_RD_CLIENT_EVENT_DISCONNECT;
|
||||
}
|
||||
|
||||
|
@ -354,7 +354,8 @@ static int do_deregister_reply_cb(const struct coap_packet *response,
|
|||
COAP_RESPONSE_CODE_DETAIL(code));
|
||||
|
||||
if (code == COAP_RESPONSE_CODE_DELETED) {
|
||||
LOG_DBG("Deregistration success");
|
||||
LOG_INF("Deregistration success");
|
||||
lwm2m_engine_context_close(client.ctx);
|
||||
set_sm_state(ENGINE_DEREGISTERED);
|
||||
} else {
|
||||
LOG_ERR("failed with code %u.%u",
|
||||
|
@ -767,6 +768,10 @@ static int sm_do_deregister(void)
|
|||
}
|
||||
|
||||
/* TODO: handle return error */
|
||||
coap_packet_append_option(&msg->cpkt, COAP_OPTION_URI_PATH,
|
||||
LWM2M_RD_CLIENT_URI,
|
||||
strlen(LWM2M_RD_CLIENT_URI));
|
||||
/* include server endpoint in URI PATH */
|
||||
coap_packet_append_option(&msg->cpkt, COAP_OPTION_URI_PATH,
|
||||
client.server_ep,
|
||||
strlen(client.server_ep));
|
||||
|
@ -861,7 +866,17 @@ void lwm2m_rd_client_start(struct lwm2m_ctx *client_ctx, const char *ep_name,
|
|||
|
||||
set_sm_state(ENGINE_INIT);
|
||||
strncpy(client.ep_name, ep_name, CLIENT_EP_LEN - 1);
|
||||
LOG_INF("LWM2M Client: %s", log_strdup(client.ep_name));
|
||||
LOG_INF("Start LWM2M Client: %s", log_strdup(client.ep_name));
|
||||
}
|
||||
|
||||
void lwm2m_rd_client_stop(struct lwm2m_ctx *client_ctx,
|
||||
lwm2m_ctx_event_cb_t event_cb)
|
||||
{
|
||||
client.ctx = client_ctx;
|
||||
client.event_cb = event_cb;
|
||||
|
||||
set_sm_state(ENGINE_DEREGISTER);
|
||||
LOG_INF("Stop LWM2M Client: %s", log_strdup(client.ep_name));
|
||||
}
|
||||
|
||||
static int lwm2m_rd_client_init(struct device *dev)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue