From 13077b9cfb2c6e77c218f87af2aa738c2e1c1ff1 Mon Sep 17 00:00:00 2001 From: NKElias Date: Tue, 18 Jun 2019 14:52:38 +0200 Subject: [PATCH] Use system clock for local offset, not timekeeping --- src/OTP/hotp.c | 4 ++-- src/OTP/report_protocol.c | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/OTP/hotp.c b/src/OTP/hotp.c index c52fcd36..fc68b3fb 100644 --- a/src/OTP/hotp.c +++ b/src/OTP/hotp.c @@ -1209,14 +1209,14 @@ time_t now; // Get the local ATMEL time time (&now); - current_time = now; if (slot_no >= NUMBER_OF_TOTP_SLOTS) return 0; OTP_slot *slot = (OTP_slot *) get_totp_slot_addr(slot_no); - time_min = current_time / slot->interval_or_counter; + // Add last time stamp from app and elapsed seconds since last set_time operation + time_min = (current_time + now) / slot->interval_or_counter; if (slot->type != 'T') // unprogrammed slot return 0; diff --git a/src/OTP/report_protocol.c b/src/OTP/report_protocol.c index 9c1c4c96..5446206a 100644 --- a/src/OTP/report_protocol.c +++ b/src/OTP/report_protocol.c @@ -2176,9 +2176,12 @@ u32 new_time_minutes = (new_time - 1388534400) / 60; // 1388534400 = 01.01.20 CI_StringOut ("Local time set to = "); itoa (new_time,text); CI_StringOut ((char*)text); CI_StringOut (" = "); ctime_r ((time_t*)&new_time,(char*)text); CI_StringOut ((char*)text); CI_StringOut ("\r\n"); } */ - set_time (new_time); - + + // Reset runtime counter and store the time offset that was received from the app + set_time (0); current_time = new_time; + + // Write new timestamp to Flash err = set_time_value (new_time_minutes); if (err) {