From 6f0213c668fdd94210516d5f36ff74a6f1bd9936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Brodbeck?= Date: Thu, 28 Jan 2021 15:15:16 +0100 Subject: [PATCH 1/2] sock/dtls: introduce function to retrieve epoch of a session --- sys/include/net/sock/dtls.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sys/include/net/sock/dtls.h b/sys/include/net/sock/dtls.h index a1a129d488eb..0b325affc14c 100644 --- a/sys/include/net/sock/dtls.h +++ b/sys/include/net/sock/dtls.h @@ -664,6 +664,19 @@ int sock_dtls_session_init(sock_dtls_t *sock, const sock_udp_ep_t *ep, */ void sock_dtls_session_destroy(sock_dtls_t *sock, sock_dtls_session_t *remote); +/** + * @brief Get the current epoch of a session. + * + * @pre `(sock != NULL) && (ep != NULL)` + * + * @param[in] sock @ref sock_dtls_t, which the session is created on + * @param[in] session @ref sock_dtls_session_t, from which the epoch is to be + * extracted + * + * @return The epoch on success + * @return -ENOTCONN, if the session is not established + */ +int16_t sock_dtls_session_get_epoch(sock_dtls_t *sock, sock_dtls_session_t *session); /** * @brief Get the remote UDP endpoint from a session. * From 02f08ffc37e0a1a511fec99e03821e96b447ce58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Brodbeck?= Date: Thu, 28 Jan 2021 15:16:04 +0100 Subject: [PATCH 2/2] pkg/tinydtls: implement sock_dtls_session_get_epoch() --- pkg/tinydtls/contrib/sock_dtls.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/tinydtls/contrib/sock_dtls.c b/pkg/tinydtls/contrib/sock_dtls.c index 912e7f044321..fc59bd0ddf72 100644 --- a/pkg/tinydtls/contrib/sock_dtls.c +++ b/pkg/tinydtls/contrib/sock_dtls.c @@ -296,6 +296,19 @@ int sock_dtls_create(sock_dtls_t *sock, sock_udp_t *udp_sock, return 0; } +int16_t sock_dtls_session_get_epoch(sock_dtls_t *sock, sock_dtls_session_t *session) +{ + assert(sock); + assert(session); + + dtls_peer_t *peer = dtls_get_peer(sock->dtls_ctx, &session->dtls_session); + if (!peer) { + return -ENOTCONN; + } + dtls_security_parameters_t *security = dtls_security_params(peer); + return security->epoch; +} + sock_udp_t *sock_dtls_get_udp_sock(sock_dtls_t *sock) { assert(sock);