Skip to content

Commit 6192ed1

Browse files
author
Seppo Takalo
committed
Compare the intermediate timestamps as well
1 parent 2229a2f commit 6192ed1

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

UNITTESTS/features/netsocket/DTLSSocket/unittest.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ set(unittest-sources
1515
../features/frameworks/nanostack-libservice/source/libip6string/ip6tos.c
1616
../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c
1717
../features/frameworks/nanostack-libservice/source/libip6string/stoip6.c
18-
../features/frameworks/nanostack-libservice/source/libBits/common_functions.c
18+
../features/frameworks/nanostack-libservice/source/libBits/common_functions.c
1919
)
2020

2121
set(unittest-test-sources
@@ -30,6 +30,7 @@ set(unittest-test-sources
3030
stubs/EventFlags_stub.cpp
3131
stubs/stoip4_stub.c
3232
stubs/ip4tos_stub.c
33+
stubs/Kernel_stub.cpp
3334
)
3435

3536
set(MBEDTLS_USER_CONFIG_FILE_PATH "\"../UNITTESTS/features/netsocket/DTLSSocket/dtls_test_config.h\"")

UNITTESTS/features/netsocket/DTLSSocketWrapper/unittest.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set(unittest-sources
1414
../features/frameworks/nanostack-libservice/source/libip6string/ip6tos.c
1515
../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c
1616
../features/frameworks/nanostack-libservice/source/libip6string/stoip6.c
17-
../features/frameworks/nanostack-libservice/source/libBits/common_functions.c
17+
../features/frameworks/nanostack-libservice/source/libBits/common_functions.c
1818
)
1919

2020
set(unittest-test-sources
@@ -29,6 +29,7 @@ set(unittest-test-sources
2929
stubs/EventFlags_stub.cpp
3030
stubs/stoip4_stub.c
3131
stubs/ip4tos_stub.c
32+
stubs/Kernel_stub.cpp
3233
)
3334

3435
set(MBEDTLS_USER_CONFIG_FILE_PATH "\"../UNITTESTS/features/netsocket/DTLSSocketWrapper/dtls_test_config.h\"")

features/netsocket/DTLSSocketWrapper.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
#include "platform/Callback.h"
33
#include "drivers/Timer.h"
44
#include "events/mbed_events.h"
5+
#include "rtos/Kernel.h"
56

67
#if defined(MBEDTLS_SSL_CLI_C)
78

8-
DTLSSocketWrapper::DTLSSocketWrapper(Socket *transport, const char *hostname, control_transport control)
9-
: TLSSocketWrapper(transport, hostname, control)
9+
DTLSSocketWrapper::DTLSSocketWrapper(Socket *transport, const char *hostname, control_transport control) :
10+
TLSSocketWrapper(transport, hostname, control),
11+
_int_ms_tick(0),
12+
_timer_event_id(0),
13+
_timer_expired(false)
1014
{
1115
mbedtls_ssl_conf_transport( get_ssl_config(), MBEDTLS_SSL_TRANSPORT_DATAGRAM);
1216
mbedtls_ssl_set_timer_cb( get_ssl_context(), this, timing_set_delay, timing_get_delay);
13-
_timer_event_id = 0;
14-
_timer_expired = false;
1517
}
1618

1719
void DTLSSocketWrapper::timing_set_delay(void *ctx, uint32_t int_ms, uint32_t fin_ms)
@@ -28,6 +30,7 @@ void DTLSSocketWrapper::timing_set_delay(void *ctx, uint32_t int_ms, uint32_t fi
2830
return;
2931
}
3032

33+
context->_int_ms_tick = rtos::Kernel::get_ms_count() + int_ms;
3134
context->_timer_event_id = mbed::mbed_event_queue()->call_in(fin_ms, context, &DTLSSocketWrapper::timer_event);
3235
}
3336

@@ -41,6 +44,8 @@ int DTLSSocketWrapper::timing_get_delay(void *ctx)
4144
return -1;
4245
} else if (context->_timer_expired) {
4346
return 2;
47+
} else if (context->_int_ms_tick < rtos::Kernel::get_ms_count()) {
48+
return 1;
4449
} else {
4550
return 0;
4651
}

features/netsocket/DTLSSocketWrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class DTLSSocketWrapper : public TLSSocketWrapper {
1313
static void timing_set_delay(void *ctx, uint32_t int_ms, uint32_t fin_ms);
1414
static int timing_get_delay(void *ctx);
1515
void timer_event();
16+
uint64_t _int_ms_tick;
1617
int _timer_event_id;
1718
bool _timer_expired:1;
1819
};

0 commit comments

Comments
 (0)