From d0d562528dd46bf23c190435a4932e39fbd67a68 Mon Sep 17 00:00:00 2001 From: kormax <3392860+kormax@users.noreply.github.com> Date: Tue, 12 May 2026 19:04:02 +0300 Subject: [PATCH] Recognize more command codes in 'hf calypso list' --- client/src/cmdhflist.c | 107 ++++++++++++++++++++++++++++++++++++++++- include/protocols.h | 5 ++ 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/client/src/cmdhflist.c b/client/src/cmdhflist.c index 9483568f6..e64eb9ee7 100644 --- a/client/src/cmdhflist.c +++ b/client/src/cmdhflist.c @@ -1014,7 +1014,7 @@ static void calypso_sfi_file_ref(char *out, size_t out_len, uint8_t p2, uint8_t } static void calypso_binary_ref(char *out, size_t out_len, uint8_t ins, uint8_t p1, uint8_t p2) { - if (ins == CALYPSO_READ_BINARY) { + if (ins == CALYPSO_READ_BINARY || ins == CALYPSO_WRITE_BINARY || ins == CALYPSO_UPDATE_BINARY) { if ((p1 & 0x80) == 0x80) { snprintf(out, out_len, "sfi=%u, off=%u", p1 & 0x1F, p2); } else { @@ -1057,6 +1057,12 @@ static bool annotateCalypsoApdu(char *exp, size_t size, const uint8_t *apdu, siz } return true; } + case CALYPSO_INVALIDATE: + snprintf(exp, size, "INVALIDATE"); + return true; + case CALYPSO_REHABILITATE: + snprintf(exp, size, "REHABILITATE"); + return true; case CALYPSO_GET_DATA: { uint16_t tag = (p1 << 8) | p2; const char *name = CalypsoGetDataTagName(tag); @@ -1067,6 +1073,36 @@ static bool annotateCalypsoApdu(char *exp, size_t size, const uint8_t *apdu, siz } return true; } + case CALYPSO_APPEND_RECORD: { + char ref[20]; + calypso_sfi_file_ref(ref, sizeof(ref), p2, 0x00, 0x00); + snprintf(exp, size, "APPEND RECORD (%s)", ref); + return true; + } + case CALYPSO_DECREASE: { + char ref[20]; + calypso_sfi_file_ref(ref, sizeof(ref), p2, 0x00, 0x00); + snprintf(exp, size, "DECREASE (%s, counter=%u)", ref, p1); + return true; + } + case CALYPSO_DECREASE_MULTIPLE: { + char ref[20]; + calypso_sfi_file_ref(ref, sizeof(ref), p2, 0x00, 0x00); + snprintf(exp, size, "DECREASE MULTIPLE (%s)", ref); + return true; + } + case CALYPSO_INCREASE: { + char ref[20]; + calypso_sfi_file_ref(ref, sizeof(ref), p2, 0x00, 0x00); + snprintf(exp, size, "INCREASE (%s, counter=%u)", ref, p1); + return true; + } + case CALYPSO_INCREASE_MULTIPLE: { + char ref[20]; + calypso_sfi_file_ref(ref, sizeof(ref), p2, 0x00, 0x00); + snprintf(exp, size, "INCREASE MULTIPLE (%s)", ref); + return true; + } case CALYPSO_READ_RECORD: { char ref[20]; calypso_sfi_file_ref(ref, sizeof(ref), p2, 0x04, 0x04); @@ -1079,6 +1115,12 @@ static bool annotateCalypsoApdu(char *exp, size_t size, const uint8_t *apdu, siz snprintf(exp, size, "READ RECORDS (%s, rec=%u)", ref, p1); return true; } + case CALYPSO_SEARCH_RECORD_MULTIPLE: { + char ref[20]; + calypso_sfi_file_ref(ref, sizeof(ref), p2, 0x07, 0x07); + snprintf(exp, size, "SEARCH RECORD (%s, rec=%u)", ref, p1); + return true; + } case CALYPSO_READ_BINARY: case CALYPSO_READ_BINARY_EXTENDED: { char ref[20]; @@ -1086,9 +1128,72 @@ static bool annotateCalypsoApdu(char *exp, size_t size, const uint8_t *apdu, siz snprintf(exp, size, "READ BINARY (%s)", ref); return true; } + case CALYPSO_WRITE_BINARY: { + char ref[20]; + calypso_binary_ref(ref, sizeof(ref), ins, p1, p2); + snprintf(exp, size, "WRITE BINARY (%s)", ref); + return true; + } + case CALYPSO_UPDATE_BINARY: { + char ref[20]; + calypso_binary_ref(ref, sizeof(ref), ins, p1, p2); + snprintf(exp, size, "UPDATE BINARY (%s)", ref); + return true; + } + case CALYPSO_UPDATE_RECORD: { + char ref[20]; + calypso_sfi_file_ref(ref, sizeof(ref), p2, 0x04, 0x04); + snprintf(exp, size, "UPDATE RECORD (%s, rec=%u)", ref, p1); + return true; + } + case CALYPSO_WRITE_RECORD: { + char ref[20]; + calypso_sfi_file_ref(ref, sizeof(ref), p2, 0x04, 0x04); + snprintf(exp, size, "WRITE RECORD (%s, rec=%u)", ref, p1); + return true; + } case CALYPSO_GET_CHALLENGE: snprintf(exp, size, "GET CHALLENGE"); return true; + case CALYPSO_OPEN_SESSION: + snprintf(exp, size, "OPEN SESSION"); + return true; + case CALYPSO_CLOSE_SESSION: + snprintf(exp, size, "CLOSE SESSION"); + return true; + case CALYPSO_VERIFY_PIN: + snprintf(exp, size, "VERIFY PIN"); + return true; + case CALYPSO_RESET_RETRY_COUNTER: + snprintf(exp, size, "RESET RETRY COUNTER"); + return true; + case CALYPSO_CHANGE_PIN: + if (p1 == 0x00 && (p2 == 0x04 || p2 == 0xFF)) { + snprintf(exp, size, "CHANGE PIN"); + } else if (p1 == 0x00 && p2 >= 0x01 && p2 <= 0x03) { + snprintf(exp, size, "CHANGE KEY"); + } else { + snprintf(exp, size, "CHANGE PIN/KEY"); + } + return true; + case CALYPSO_SV_GET: + snprintf(exp, size, "SV GET"); + return true; + case CALYPSO_SV_DEBIT: + snprintf(exp, size, "SV DEBIT (challenge=%02X%02X)", p1, p2); + return true; + case CALYPSO_SV_RELOAD: + snprintf(exp, size, "SV RELOAD (challenge=%02X%02X)", p1, p2); + return true; + case CALYPSO_SV_UN_DEBIT: + snprintf(exp, size, "SV UNDEBIT (challenge=%02X%02X)", p1, p2); + return true; + case CALYPSO_SAM_SV_DEBIT: + snprintf(exp, size, "SAM SV DEBIT"); + return true; + case CALYPSO_SAM_SV_RELOAD: + snprintf(exp, size, "SAM SV RELOAD"); + return true; case CALYPSO_GET_RESPONSE: snprintf(exp, size, "GET RESPONSE"); return true; diff --git a/include/protocols.h b/include/protocols.h index bebb4349f..df25a3cf7 100644 --- a/include/protocols.h +++ b/include/protocols.h @@ -935,17 +935,22 @@ ISO 7816-4 Basic interindustry commands. For command APDU's. #define CALYPSO_REHABILITATE 0x44 #define CALYPSO_APPEND_RECORD 0xE2 #define CALYPSO_DECREASE 0x30 +#define CALYPSO_DECREASE_MULTIPLE 0x38 #define CALYPSO_INCREASE 0x32 +#define CALYPSO_INCREASE_MULTIPLE 0x3A #define CALYPSO_READ_BINARY 0xB0 #define CALYPSO_READ_BINARY_EXTENDED 0xB1 #define CALYPSO_READ_RECORD 0xB2 #define CALYPSO_READ_RECORD_MULTIPLE 0xB3 +#define CALYPSO_SEARCH_RECORD_MULTIPLE 0xA2 +#define CALYPSO_WRITE_BINARY 0xD0 #define CALYPSO_UPDATE_BINARY 0xD6 #define CALYPSO_UPDATE_RECORD 0xDC #define CALYPSO_WRITE_RECORD 0xD2 #define CALYPSO_OPEN_SESSION 0x8A #define CALYPSO_CLOSE_SESSION 0x8E #define CALYPSO_GET_CHALLENGE 0x84 +#define CALYPSO_RESET_RETRY_COUNTER 0x2C #define CALYPSO_CHANGE_PIN 0xD8 #define CALYPSO_VERIFY_PIN 0x20 #define CALYPSO_SV_GET 0x7C