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: https://github.com/zephyrproject-rtos/zephyr/issues/17408 Signed-off-by: Michael Scott <mike@foundries.io>
This commit is contained in:
parent
d7e49ee3e7
commit
e7155622a2
2 changed files with 19 additions and 7 deletions
|
@ -71,6 +71,11 @@ struct lwm2m_ctx {
|
||||||
* LwM2M engine calls tls_credential_(add|delete)
|
* LwM2M engine calls tls_credential_(add|delete)
|
||||||
*/
|
*/
|
||||||
int tls_tag;
|
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
|
#endif
|
||||||
/** Flag to indicate if context should use DTLS.
|
/** Flag to indicate if context should use DTLS.
|
||||||
* Enabled via the use of coaps:// protocol prefix in connection
|
* 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)
|
#if defined(CONFIG_LWM2M_DTLS_SUPPORT)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = load_tls_credential(client_ctx, 3, TLS_CREDENTIAL_PSK_ID);
|
if (client_ctx->load_credentials) {
|
||||||
if (ret < 0) {
|
ret = client_ctx->load_credentials(client_ctx);
|
||||||
return ret;
|
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);
|
ret = load_tls_credential(client_ctx, 5, TLS_CREDENTIAL_PSK);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client_ctx->use_dtls) {
|
if (client_ctx->use_dtls) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue