Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-client-mbedtls by
Diff: source/m2mconnectionsecuritypimpl.cpp
- Revision:
- 5:840aa460b437
- Parent:
- 4:1ca4b8bd7dd2
- Child:
- 6:80a66815c791
--- a/source/m2mconnectionsecuritypimpl.cpp	Mon Apr 04 17:31:06 2016 +0300
+++ b/source/m2mconnectionsecuritypimpl.cpp	Thu Apr 07 02:01:28 2016 +0300
@@ -40,7 +40,7 @@
 {
     _init_done = false;
     cancelled = true;
-    _timmer = new M2MTimer(*this);
+    _timer = new M2MTimer(*this);
     mbedtls_ssl_init( &_ssl );
     mbedtls_ssl_config_init( &_conf );
     mbedtls_x509_crt_init( &_cacert );
@@ -58,7 +58,7 @@
     mbedtls_pk_free(&_pkey);
     mbedtls_ctr_drbg_free( &_ctr_drbg );
     mbedtls_entropy_free( &_entropy );
-    delete _timmer;
+    delete _timer;
 }
 
 void M2MConnectionSecurityPimpl::timer_expired(M2MTimerObserver::Type type){
@@ -91,7 +91,7 @@
     mbedtls_pk_free(&_pkey);
     mbedtls_ctr_drbg_free( &_ctr_drbg );
     mbedtls_entropy_free( &_entropy );
-    _timmer->stop_timer();
+    _timer->stop_timer();
 }
 
 int M2MConnectionSecurityPimpl::init(const M2MSecurity *security){
@@ -231,16 +231,10 @@
        return -1;
     }
 
-    //TODO: check is this needed
-//    if( ( ret = mbedtls_ssl_set_hostname( &_ssl, "linux-secure-endpoint" ) ) != 0 )
-//    {
-//       return -1;
-//    }
+    mbedtls_ssl_set_bio( &_ssl, connHandler,
+                        f_send, NULL, f_recv_timeout );
 
-    mbedtls_ssl_set_bio( &_ssl, connHandler,
-                        f_send, f_recv, f_recv_timeout );
-
-    mbedtls_ssl_set_timer_cb( &_ssl, _timmer, mbedtls_timing_set_delay,
+    mbedtls_ssl_set_timer_cb( &_ssl, _timer, mbedtls_timing_set_delay,
                                             mbedtls_timing_get_delay );
 
     do ret = mbedtls_ssl_handshake( &_ssl );
@@ -250,6 +244,7 @@
     tr_debug("M2MConnectionSecurityPimpl::connect - handshake, ret: %d", ret);
 
     if( ret != 0 ) {
+        tr_error("M2MConnectionSecurityPimpl::connect - handshake failed");
         ret = -1;
     }else {
         if( ( _flags = mbedtls_ssl_get_verify_result( &_ssl ) ) != 0 ) {
@@ -291,9 +286,9 @@
     }
 
     mbedtls_ssl_set_bio( &_ssl, connHandler,
-                        f_send, f_recv, f_recv_timeout );
+                        f_send, f_recv, NULL );
 
-    mbedtls_ssl_set_timer_cb( &_ssl, _timmer, mbedtls_timing_set_delay,
+    mbedtls_ssl_set_timer_cb( &_ssl, _timer, mbedtls_timing_set_delay,
                                             mbedtls_timing_get_delay );
 
     ret = mbedtls_ssl_handshake_step( &_ssl );
@@ -377,8 +372,9 @@
     return handler->receive_from_socket(buf, len);
 }
 
-int f_recv_timeout(void *ctx, unsigned char *buf, size_t len, uint32_t /*some*/){
-    return f_recv(ctx, buf, len);
+int f_recv_timeout(void *ctx, unsigned char *buf, size_t len, uint32_t timeout){
+    M2MConnectionHandler* handler = ((M2MConnectionHandler *) ctx);
+    return handler->receive_from_socket(buf, len, timeout);
 }
 
 int entropy_poll( void *, unsigned char *output, size_t len,
    