[riot-notifications] [RIOT-OS/RIOT] tinydtls: add `sock_async` support for `sock_dtls` (#12907)

Aiman Ismail notifications at github.com
Mon May 25 17:33:52 CEST 2020

tinydtls emits an event `DTLS_EVENT_CONNECTED` when a handshake is completed, but there are no application data decrypted. So the `sock_dtls_recv` in `SOCK_ASYNC_CONN_RECV` handler is not needed. The current code fails when calling `sock_dtls_recv` because there is no data to be received yet.

But without the `sock_dtls_recv`, we now have another issue - we don't know which session to send the data to because the `sock_dtls_session_t` struct is not filled in for us. We need to have access to the members of `sock_dtls_session_t` that is passed to `sock_dtls_session_init`.


One way that I've tried is by passing a new struct containing the `sock_dtls_session_t` and the data to be sent to `_dtls_handler`. With this I can send the message, but the server got a FAILED ASSERTION when echoing the message back.

# declarations
struct test {
    sock_dtls_session_t *session;
    void *data;

# in client_send()
sock_dtls_session_t session;
[fill in session...]

struct test params = {
    .session = &session,
    .data = data, # data to be sent
sock_dtls_event_init(&_dtls_sock, &event_queue_medium, _dtls_handler, (void *)&params);

# in _dtls_handler()
  if (type & SOCK_ASYNC_CONN_RECV) {
        puts("Connection to server successful");
        struct test *info = (struct test *)arg;
        sock_dtls_session_t *session_new = info->session;
        int res = sock_dtls_send(sock, session_new, info->data, strlen(info->data), 0);
        if (res < 0) {
             #close session/sock
        else {
            printf("Sent DTLS message\n");

You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20200525/79455989/attachment-0001.htm>

More information about the notifications mailing list