Skip to content

Commit 4d0e800

Browse files
andi-exactSeppoTakalo
authored andcommitted
[nrf fromtree] 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]> (cherry picked from commit 9c24214)
1 parent 92454e3 commit 4d0e800

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.
@@ -258,7 +259,7 @@ struct lwm2m_ctx {
258259
* a callback that is called after a socket is created and before
259260
* connect.
260261
*/
261-
int (*set_socketoptions)(struct lwm2m_ctx *client_ctx);
262+
lwm2m_set_sockopt_cb_t set_socketoptions;
262263

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

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