Skip to content
Permalink
Browse files

net: lwm2m: add custom TLS credential load function pointer

Current implementation of LwM2M engine doesn't allow users a way
of overriding TLS credential load with custom function.  This
would be needed by an offloaded TLS stack where we don't want
to use standard Zephyr functions.

Let's add a load_credential function pointer to the LwM2M client
context which will be called when it's available.

Fixes: #17408

Signed-off-by: Michael Scott <mike@foundries.io>
  • Loading branch information...
mike-scott authored and jukkar committed Jul 8, 2019
1 parent d7e49ee commit e7155622a288da924f2fca06ba9a51c1202ea387
Showing with 19 additions and 7 deletions.
  1. +5 −0 include/net/lwm2m.h
  2. +14 −7 subsys/net/lib/lwm2m/lwm2m_engine.c
@@ -71,6 +71,11 @@ struct lwm2m_ctx {
* LwM2M engine calls tls_credential_(add|delete)
*/
int tls_tag;

/** Client can set load_credentials function as a way of overriding
* the default behavior of load_tls_credential() in lwm2m_engine.c
*/
int (*load_credentials)(struct lwm2m_ctx *client_ctx);
#endif
/** Flag to indicate if context should use DTLS.
* Enabled via the use of coaps:// protocol prefix in connection
@@ -3992,14 +3992,21 @@ int lwm2m_socket_start(struct lwm2m_ctx *client_ctx)
#if defined(CONFIG_LWM2M_DTLS_SUPPORT)
int ret;

ret = load_tls_credential(client_ctx, 3, TLS_CREDENTIAL_PSK_ID);
if (ret < 0) {
return ret;
}
if (client_ctx->load_credentials) {
ret = client_ctx->load_credentials(client_ctx);
if (ret < 0) {
return ret;
}
} else {
ret = load_tls_credential(client_ctx, 3, TLS_CREDENTIAL_PSK_ID);
if (ret < 0) {
return ret;
}

ret = load_tls_credential(client_ctx, 5, TLS_CREDENTIAL_PSK);
if (ret < 0) {
return ret;
ret = load_tls_credential(client_ctx, 5, TLS_CREDENTIAL_PSK);
if (ret < 0) {
return ret;
}
}

if (client_ctx->use_dtls) {

0 comments on commit e715562

Please sign in to comment.
You can’t perform that action at this time.