net: lwm2m: Make bootstrap optional
Currently, after `CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP` is enabled, the LwM2M engine will initiate bootstrap procedure on each run. This approach limits the flexibility of the application, as it's not always necessary to go over the bootstrap procedure (for instance, the application may decide to store the security object obtained during the bootstrap in flash, and restore it on boot). Fix this by introducing an additional `flags` parameter to the `lwm2m_rd_client_start()` function, which provides information whether to run bootstrap in the current session or not. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
parent
40d25b8efa
commit
f7a5638871
5 changed files with 35 additions and 7 deletions
|
@ -361,7 +361,7 @@ endpoint name. This is important as it needs to be unique per LwM2M server:
|
|||
.. code-block:: c
|
||||
|
||||
(void)memset(&client, 0x0, sizeof(client));
|
||||
lwm2m_rd_client_start(&client, "unique-endpoint-name", rd_client_event);
|
||||
lwm2m_rd_client_start(&client, "unique-endpoint-name", 0, rd_client_event);
|
||||
|
||||
Using LwM2M library with DTLS
|
||||
*****************************
|
||||
|
@ -406,7 +406,7 @@ value of 1 is ok here).
|
|||
|
||||
(void)memset(&client, 0x0, sizeof(client));
|
||||
client.tls_tag = 1; /* <---- */
|
||||
lwm2m_rd_client_start(&client, "endpoint-name", rd_client_event);
|
||||
lwm2m_rd_client_start(&client, "endpoint-name", 0, rd_client_event);
|
||||
|
||||
For a more detailed LwM2M client sample see: :ref:`lwm2m-client-sample`.
|
||||
|
||||
|
|
|
@ -32,6 +32,10 @@ API Changes
|
|||
* Removed SETTINGS_USE_BASE64 support as its been deprecated for more than
|
||||
two releases.
|
||||
|
||||
* The :c:func:`lwm2m_rd_client_start` function now accepts an additional
|
||||
``flags`` parameter, which allows to configure current LwM2M client session,
|
||||
for instance enable bootstrap procedure in the curent session.
|
||||
|
||||
Deprecated in this release
|
||||
==========================
|
||||
|
||||
|
|
|
@ -850,6 +850,15 @@ enum lwm2m_rd_client_event {
|
|||
LWM2M_RD_CLIENT_EVENT_QUEUE_MODE_RX_OFF,
|
||||
};
|
||||
|
||||
/*
|
||||
* LwM2M RD client flags, used to configure LwM2M session.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Run bootstrap procedure in current session.
|
||||
*/
|
||||
#define LWM2M_RD_CLIENT_FLAG_BOOTSTRAP BIT(0)
|
||||
|
||||
/**
|
||||
* @brief Asynchronous RD client event callback
|
||||
*
|
||||
|
@ -871,12 +880,13 @@ typedef void (*lwm2m_ctx_event_cb_t)(struct lwm2m_ctx *ctx,
|
|||
*
|
||||
* @param[in] client_ctx LwM2M context
|
||||
* @param[in] ep_name Registered endpoint name
|
||||
* @param[in] flags Flags used to configure current LwM2M session.
|
||||
* @param[in] event_cb Client event callback function
|
||||
*
|
||||
* @return 0 for success or negative in case of error.
|
||||
*/
|
||||
void lwm2m_rd_client_start(struct lwm2m_ctx *client_ctx, const char *ep_name,
|
||||
lwm2m_ctx_event_cb_t event_cb);
|
||||
uint32_t flags, lwm2m_ctx_event_cb_t event_cb);
|
||||
|
||||
/**
|
||||
* @brief Stop the LwM2M RD (De-register) Client
|
||||
|
|
|
@ -423,6 +423,8 @@ static void rd_client_event(struct lwm2m_ctx *client,
|
|||
|
||||
void main(void)
|
||||
{
|
||||
uint32_t flags = IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) ?
|
||||
LWM2M_RD_CLIENT_FLAG_BOOTSTRAP : 0;
|
||||
int ret;
|
||||
|
||||
LOG_INF(APP_BANNER);
|
||||
|
@ -461,10 +463,10 @@ void main(void)
|
|||
sprintf(&dev_str[i*2], "%02x", dev_id[i]);
|
||||
}
|
||||
|
||||
lwm2m_rd_client_start(&client, dev_str, rd_client_event);
|
||||
lwm2m_rd_client_start(&client, dev_str, flags, rd_client_event);
|
||||
#else
|
||||
/* client.sec_obj_inst is 0 as a starting point */
|
||||
lwm2m_rd_client_start(&client, CONFIG_BOARD, rd_client_event);
|
||||
lwm2m_rd_client_start(&client, CONFIG_BOARD, flags, rd_client_event);
|
||||
#endif
|
||||
|
||||
k_sem_take(&quit_lock, K_FOREVER);
|
||||
|
|
|
@ -503,7 +503,11 @@ static int sm_do_init(void)
|
|||
|
||||
/* Do bootstrap or registration */
|
||||
#if defined(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP)
|
||||
set_sm_state(ENGINE_DO_BOOTSTRAP_REG);
|
||||
if (client.use_bootstrap) {
|
||||
set_sm_state(ENGINE_DO_BOOTSTRAP_REG);
|
||||
} else {
|
||||
set_sm_state(ENGINE_DO_REGISTRATION);
|
||||
}
|
||||
#else
|
||||
set_sm_state(ENGINE_DO_REGISTRATION);
|
||||
#endif
|
||||
|
@ -926,11 +930,19 @@ static void lwm2m_rd_client_service(struct k_work *work)
|
|||
}
|
||||
|
||||
void lwm2m_rd_client_start(struct lwm2m_ctx *client_ctx, const char *ep_name,
|
||||
lwm2m_ctx_event_cb_t event_cb)
|
||||
uint32_t flags, lwm2m_ctx_event_cb_t event_cb)
|
||||
{
|
||||
if (!IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) &&
|
||||
(flags & LWM2M_RD_CLIENT_FLAG_BOOTSTRAP)) {
|
||||
LOG_ERR("Bootstrap support is disabled. Please enable "
|
||||
"CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP.");
|
||||
return;
|
||||
}
|
||||
|
||||
client.ctx = client_ctx;
|
||||
client.ctx->sock_fd = -1;
|
||||
client.event_cb = event_cb;
|
||||
client.use_bootstrap = flags & LWM2M_RD_CLIENT_FLAG_BOOTSTRAP;
|
||||
|
||||
set_sm_state(ENGINE_INIT);
|
||||
strncpy(client.ep_name, ep_name, CLIENT_EP_LEN - 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue