Skip to content

Commit 9c24214

Browse files
andi-exactnashif
authored andcommitted
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 <[email protected]>
1 parent e6c9e9a commit 9c24214

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

include/zephyr/net/lwm2m.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ enum lwm2m_rd_client_event {
182182
typedef void (*lwm2m_ctx_event_cb_t)(struct lwm2m_ctx *ctx,
183183
enum lwm2m_rd_client_event event);
184184

185+
typedef int (*lwm2m_set_sockopt_cb_t)(struct lwm2m_ctx *client_ctx);
185186

186187
/**
187188
* @brief Different traffic states of the LwM2M socket.
@@ -259,7 +260,7 @@ struct lwm2m_ctx {
259260
* a callback that is called after a socket is created and before
260261
* connect.
261262
*/
262-
int (*set_socketoptions)(struct lwm2m_ctx *client_ctx);
263+
lwm2m_set_sockopt_cb_t set_socketoptions;
263264

264265
/** Flag to indicate if context should use DTLS.
265266
* Enabled via the use of coaps:// protocol prefix in connection
@@ -1622,6 +1623,17 @@ int lwm2m_security_mode(struct lwm2m_ctx *ctx);
16221623
*/
16231624
int lwm2m_set_default_sockopt(struct lwm2m_ctx *ctx);
16241625

1626+
/**
1627+
* @brief Set the @ref lwm2m_ctx::set_socketoptions callback for the pull context's client.
1628+
*
1629+
* This allows setting specific socket options on the socket that is used to pull
1630+
* firmware updates. The callback will be called after the pull context socket has been
1631+
* created and before it will connect.
1632+
*
1633+
* @param[in] set_sockopt_cb A callback function to set sockopts for the pull context client.
1634+
*/
1635+
void lwm2m_pull_context_set_sockopt_callback(lwm2m_set_sockopt_cb_t set_sockopt_cb);
1636+
16251637
#ifdef __cplusplus
16261638
}
16271639
#endif

subsys/net/lib/lwm2m/lwm2m_pull_context.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,15 @@ int lwm2m_pull_context_start_transfer(char *uri, struct requesting_object req, k
446446
context.result_cb = req.result_cb;
447447
context.write_cb = req.write_cb;
448448

449-
(void)memset(&context.firmware_ctx, 0, sizeof(struct lwm2m_ctx));
450449
(void)memset(&context.block_ctx, 0, sizeof(struct coap_block_context));
451450
context.firmware_ctx.sock_fd = -1;
452451

453452
firmware_transfer();
454453

455454
return 0;
456455
}
456+
457+
void lwm2m_pull_context_set_sockopt_callback(lwm2m_set_sockopt_cb_t set_sockopt_cb)
458+
{
459+
context.firmware_ctx.set_socketoptions = set_sockopt_cb;
460+
}

0 commit comments

Comments
 (0)