34#include "mbedtls/private_access.h"
35#include "timing_alt.h"
39#define LOG_MODULE "DTLS"
40#define LOG_LEVEL LOG_LEVEL_NONE
42volatile int mbedtls_timing_alarmed;
43static struct ctimer alarm_timer;
47alarm_callback(
void *ptr)
49 LOG_DBG(
"Triggered an alarm\n");
50 mbedtls_timing_alarmed = 1;
54mbedtls_set_alarm(
int seconds)
56 LOG_DBG(
"Set alarm in %d seconds\n", seconds);
57 mbedtls_timing_alarmed = 0;
62mbedtls_timing_get_delay(
void *data)
64 struct mbedtls_timing_delay_context *ctx =
65 (
struct mbedtls_timing_delay_context *)data;
66 unsigned long elapsed_ms =
67 mbedtls_timing_get_timer(&ctx->MBEDTLS_PRIVATE(
timer), 0);
69 if(ctx->MBEDTLS_PRIVATE(fin_ms) == 0) {
73 if(elapsed_ms > ctx->MBEDTLS_PRIVATE(fin_ms)) {
75 LOG_DBG(
"%s: the final delay has passed. %lu > %"PRIu32
"\n",
76 __func__, elapsed_ms, ctx->MBEDTLS_PRIVATE(fin_ms));
80 if(elapsed_ms > ctx->MBEDTLS_PRIVATE(int_ms)) {
82 LOG_DBG(
"%s: the intermediate delay has passed. %lu > %"PRIu32
"\n",
83 __func__, elapsed_ms, ctx->MBEDTLS_PRIVATE(int_ms));
88 LOG_DBG(
"%s: no delay has passed. elapsed ms %lu, fin ms %"PRIu32
", int ms %"PRIu32
"\n",
90 ctx->MBEDTLS_PRIVATE(fin_ms), ctx->MBEDTLS_PRIVATE(int_ms));
95mbedtls_timing_get_timer(
struct mbedtls_timing_hr_time *val,
int reset)
105mbedtls_timing_hardclock(
void)
113mbedtls_timing_set_delay(
void *data, uint32_t int_ms, uint32_t fin_ms)
115 struct mbedtls_timing_delay_context *ctx;
117 ctx = (
struct mbedtls_timing_delay_context *)data;
121 ctx->MBEDTLS_PRIVATE(int_ms) = int_ms;
122 ctx->MBEDTLS_PRIVATE(fin_ms) = fin_ms;
clock_time_t clock_time(void)
Get the current clock time.
#define CLOCK_SECOND
A second, measured in system clock time.
static void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
#define RTIMER_NOW()
Get the current clock time.
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
void timer_reset(struct timer *t)
Reset the timer with the same interval.
Header file for the logging system.