From 9c2421444ba51c812eaa579e8f7a859e73b78bfa Mon Sep 17 00:00:00 2001 From: Andi Gerl Date: Fri, 8 Nov 2024 15:23:28 -0500 Subject: [PATCH] net: lwm2m: add set_socketoptions cb to pull context LwM2M context The pull context LwM2M client's set_socketoptions callback is currently unused and can't be set by a user. Add a public API to set the pull context's client's set_socketoptions callback. Signed-off-by: Andi Gerl --- include/zephyr/net/lwm2m.h | 14 +++++++++++++- subsys/net/lib/lwm2m/lwm2m_pull_context.c | 6 +++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/zephyr/net/lwm2m.h b/include/zephyr/net/lwm2m.h index 9c4590a2767..4aa81a8bcf6 100644 --- a/include/zephyr/net/lwm2m.h +++ b/include/zephyr/net/lwm2m.h @@ -182,6 +182,7 @@ enum lwm2m_rd_client_event { typedef void (*lwm2m_ctx_event_cb_t)(struct lwm2m_ctx *ctx, enum lwm2m_rd_client_event event); +typedef int (*lwm2m_set_sockopt_cb_t)(struct lwm2m_ctx *client_ctx); /** * @brief Different traffic states of the LwM2M socket. @@ -259,7 +260,7 @@ struct lwm2m_ctx { * a callback that is called after a socket is created and before * connect. */ - int (*set_socketoptions)(struct lwm2m_ctx *client_ctx); + lwm2m_set_sockopt_cb_t set_socketoptions; /** Flag to indicate if context should use DTLS. * Enabled via the use of coaps:// protocol prefix in connection @@ -1622,6 +1623,17 @@ int lwm2m_security_mode(struct lwm2m_ctx *ctx); */ int lwm2m_set_default_sockopt(struct lwm2m_ctx *ctx); +/** + * @brief Set the @ref lwm2m_ctx::set_socketoptions callback for the pull context's client. + * + * This allows setting specific socket options on the socket that is used to pull + * firmware updates. The callback will be called after the pull context socket has been + * created and before it will connect. + * + * @param[in] set_sockopt_cb A callback function to set sockopts for the pull context client. + */ +void lwm2m_pull_context_set_sockopt_callback(lwm2m_set_sockopt_cb_t set_sockopt_cb); + #ifdef __cplusplus } #endif diff --git a/subsys/net/lib/lwm2m/lwm2m_pull_context.c b/subsys/net/lib/lwm2m/lwm2m_pull_context.c index 356f19705f5..8081c3793ed 100644 --- a/subsys/net/lib/lwm2m/lwm2m_pull_context.c +++ b/subsys/net/lib/lwm2m/lwm2m_pull_context.c @@ -446,7 +446,6 @@ int lwm2m_pull_context_start_transfer(char *uri, struct requesting_object req, k context.result_cb = req.result_cb; context.write_cb = req.write_cb; - (void)memset(&context.firmware_ctx, 0, sizeof(struct lwm2m_ctx)); (void)memset(&context.block_ctx, 0, sizeof(struct coap_block_context)); context.firmware_ctx.sock_fd = -1; @@ -454,3 +453,8 @@ int lwm2m_pull_context_start_transfer(char *uri, struct requesting_object req, k return 0; } + +void lwm2m_pull_context_set_sockopt_callback(lwm2m_set_sockopt_cb_t set_sockopt_cb) +{ + context.firmware_ctx.set_socketoptions = set_sockopt_cb; +}