From 52625ec1de683b011aba1da55489db710c8a7049 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 15 Jun 2019 16:20:59 +0200 Subject: [PATCH] Return counter in text for backward compatibility. Allow to request new format. Signed-off-by: Szczepan Zalega --- src/OTP/report_protocol.c | 15 ++++++++++++--- src/OTP/report_protocol.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/OTP/report_protocol.c b/src/OTP/report_protocol.c index 08339a3c..9c97aa28 100644 --- a/src/OTP/report_protocol.c +++ b/src/OTP/report_protocol.c @@ -1574,7 +1574,9 @@ u8 slot_no = report[1]; u8 cmd_read_slot (u8 * report, u8 * output) { u8 slot_no = report[CMD_RS_SLOT_NUMBER_OFFSET]; +u8 format_version = report[CMD_RS_VERSION_OFFSET]; u64 counter; +char buf[20] = {}; if (is_HOTP_slot_number(slot_no)) // HOTP slot { @@ -1587,9 +1589,16 @@ u64 counter; memcpy (output + OUTPUT_CMD_RESULT_OFFSET + 16, slot->token_id, 13); output[OUTPUT_CMD_RESULT_OFFSET +15] = slot->config; - counter = get_counter_value (hotp_slot_counters[slot_no]); - counter = endian_swap(counter); - memcpy (output + OUTPUT_CMD_RESULT_OFFSET + 29, &counter, sizeof(u64)); + counter = get_counter_value(hotp_slot_counters[slot_no]); + if (format_version == 1) { + counter = endian_swap(counter); + memcpy (output + OUTPUT_CMD_RESULT_OFFSET + 29, &counter, sizeof(u64)); + } else { + itoa(counter, buf); + buf[7] = 0; + memcpy (output + OUTPUT_CMD_RESULT_OFFSET + 29, buf, 8); + } + { u8 text[20]; diff --git a/src/OTP/report_protocol.h b/src/OTP/report_protocol.h index 277c914b..f5a6b594 100644 --- a/src/OTP/report_protocol.h +++ b/src/OTP/report_protocol.h @@ -307,6 +307,7 @@ typedef struct { */ #define CMD_RS_SLOT_NUMBER_OFFSET 1 +#define CMD_RS_VERSION_OFFSET 2 #define CMD_RS_OUTPUT_COUNTER_OFFSET 34 /*