@@ -37,16 +37,33 @@ bool DtlsUdp::connect(IPAddress ip, int port) {
3737 sprintf (ipstr, " %d.%d.%d.%d" , ip[0 ], ip[1 ], ip[2 ], ip[3 ]);
3838 char portstr[8 ];
3939 snprintf (portstr, sizeof (portstr), " %d" , port);
40- if (mbedtls_net_connect (&net_ctx, ipstr, portstr, MBEDTLS_NET_PROTO_UDP) != 0 ) return false ;
41- if (mbedtls_ssl_config_defaults (&conf, MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_TRANSPORT_DATAGRAM, MBEDTLS_SSL_PRESET_DEFAULT) != 0 ) return false ;
40+ int ret;
41+ ret = mbedtls_net_connect (&net_ctx, ipstr, portstr, MBEDTLS_NET_PROTO_UDP);
42+ Serial.print (" mbedtls_net_connect returned: " );
43+ Serial.println (ret);
44+ if (ret != 0 ) return false ;
45+ ret = mbedtls_ssl_config_defaults (&conf, MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_TRANSPORT_DATAGRAM, MBEDTLS_SSL_PRESET_DEFAULT);
46+ Serial.print (" mbedtls_ssl_config_defaults returned: " );
47+ Serial.println (ret);
48+ if (ret != 0 ) return false ;
4249 mbedtls_ssl_conf_authmode (&conf, MBEDTLS_SSL_VERIFY_NONE);
4350 mbedtls_ssl_conf_rng (&conf, mbedtls_ctr_drbg_random, &ctr_drbg);
44- if (mbedtls_ssl_setup (&ssl, &conf) != 0 ) return false ;
51+ ret = mbedtls_ssl_setup (&ssl, &conf);
52+ Serial.print (" mbedtls_ssl_setup returned: " );
53+ Serial.println (ret);
54+ if (ret != 0 ) return false ;
4555 mbedtls_ssl_set_bio (&ssl, &net_ctx, mbedtls_net_send, mbedtls_net_recv, NULL );
4656 // DTLS handshake
47- int ret;
4857 do {
4958 ret = mbedtls_ssl_handshake (&ssl);
59+ Serial.print (" mbedtls_ssl_handshake returned: " );
60+ Serial.println (ret);
61+ if (ret != 0 && ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
62+ char errbuf[128 ];
63+ mbedtls_strerror (ret, errbuf, sizeof (errbuf));
64+ Serial.print (" mbedtls_ssl_handshake error: " );
65+ Serial.println (errbuf);
66+ }
5067 } while (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE);
5168 connected = (ret == 0 );
5269 return connected;
0 commit comments