diff --git a/pkg/tinydtls/contrib/sock_dtls.c b/pkg/tinydtls/contrib/sock_dtls.c index 3885f786ab..8aa00d3de1 100644 --- a/pkg/tinydtls/contrib/sock_dtls.c +++ b/pkg/tinydtls/contrib/sock_dtls.c @@ -345,6 +345,24 @@ void sock_dtls_session_destroy(sock_dtls_t *sock, sock_dtls_session_t *remote) dtls_close(sock->dtls_ctx, &remote->dtls_session); } +void sock_dtls_session_get_udp_ep(const sock_dtls_session_t *session, + sock_udp_ep_t *ep) +{ + assert(session); + assert(ep); + + _session_to_ep(&session->dtls_session, ep); +} + +void sock_dtls_session_set_udp_ep(sock_dtls_session_t *session, + const sock_udp_ep_t *ep) +{ + assert(session); + assert(ep); + + _ep_to_session(ep, &session->dtls_session); +} + ssize_t sock_dtls_send_aux(sock_dtls_t *sock, sock_dtls_session_t *remote, const void *data, size_t len, uint32_t timeout, sock_dtls_aux_tx_t *aux) diff --git a/sys/include/net/sock/dtls.h b/sys/include/net/sock/dtls.h index efc0c49773..a1a129d488 100644 --- a/sys/include/net/sock/dtls.h +++ b/sys/include/net/sock/dtls.h @@ -664,6 +664,31 @@ 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 remote UDP endpoint from a session. + * + * @pre `(session != NULL) && (ep != NULL)` + * + * @param[in] session DTLS session + * @param[out] ep UDP endpoint + */ +void sock_dtls_session_get_udp_ep(const sock_dtls_session_t *session, + sock_udp_ep_t *ep); + +/** + * @brief Set the remote UDP endpoint from a session. + * + * @pre `(session != NULL) && (ep != NULL)` + * + * @param[in] session DTLS session + * @param[in] ep UDP endpoint + * + * @note Function should only be needed when doing a blocking handshake with + * @ref sock_dtls_send() to set the remote UDP endpoint. + */ +void sock_dtls_session_set_udp_ep(sock_dtls_session_t *session, + const sock_udp_ep_t *ep); + /** * @brief Receive handshake messages and application data from remote peer. * @@ -882,6 +907,14 @@ ssize_t sock_dtls_send_aux(sock_dtls_t *sock, sock_dtls_session_t *remote, * @note When blocking, we will need an extra thread to call * @ref sock_dtls_recv() function to handle the incoming handshake * messages. + * An example for a blocking handshake is: + * 1. Create an empty @ref sock_dtls_session_t object. + * 2. Set the UDP endpoint of the peer you want to connect to in the + * session object with @ref sock_dtls_session_set_udp_ep(). + * 3. Call @ref sock_dtls_send() with a timeout greater than 0. + * The send function blocks until the handshake completes or the + * timeout expires. If the handshake was successful the data has + * been sent. * * @return The number of bytes sent on success * @return -ENOTCONN, if `timeout == 0` and no existing session exists with