From cec963b9bad7ebad55daee157e5632b2f71b949f Mon Sep 17 00:00:00 2001 From: kormax <3392860+kormax@users.noreply.github.com> Date: Sat, 1 Aug 2026 12:41:48 +0300 Subject: [PATCH] Annotate FeliCa SEAC request and response traces --- client/src/cmdhflist.c | 40 +++++++++++++++++++++++++++++++++++++++- client/src/cmdhflist.h | 2 +- client/src/cmdtrace.c | 6 +++--- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/client/src/cmdhflist.c b/client/src/cmdhflist.c index b510647f1..542015737 100644 --- a/client/src/cmdhflist.c +++ b/client/src/cmdhflist.c @@ -2443,12 +2443,50 @@ void annotateLegic(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) { } } -void annotateFelica(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) { +static bool annotateFelicaSeac(char *exp, size_t size, const uint8_t *cmd, uint8_t cmdsize, bool is_response) { + if (cmdsize < 7 || cmd[4] != 0x01 || cmd[5] != 0x01 || + (cmd[6] != 0x01 && cmd[6] < 0x0F)) { + return false; + } + + const char *operation = NULL; + switch (cmd[3]) { + case FELICA_SEAC_POLLING_CMD: + operation = "POLLING"; + break; + case FELICA_SEAC_AUTHENTICATION1_CMD: + operation = "AUTHENTICATION1"; + break; + case FELICA_SEAC_AUTHENTICATION2_CMD: + operation = "AUTHENTICATION2"; + break; + case FELICA_SEAC_WRITE_CMD: + operation = "WRITE"; + break; + case FELICA_SEAC_READ_CMD: + operation = "READ"; + break; + case FELICA_SEAC_EXTENDED_CMD: + operation = "EXTENDED"; + break; + default: + return false; + } + + snprintf(exp, size, "SEAC %s %s (SELECTOR %02X)", operation, is_response ? "RES" : "REQ", cmd[6]); + return true; +} + +void annotateFelica(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool is_response) { if (cmdsize < 4) { snprintf(exp, size, "?"); return; } + if (annotateFelicaSeac(exp, size, cmd, cmdsize, is_response)) { + return; + } + uint16_t cmd_code = cmd[3]; if (cmd_code >= 0xC0 && cmdsize > 4) { // Command codes >= 0xC0 include a second-byte subcommand/function code. diff --git a/client/src/cmdhflist.h b/client/src/cmdhflist.h index c975f9863..a32305504 100644 --- a/client/src/cmdhflist.h +++ b/client/src/cmdhflist.h @@ -54,7 +54,7 @@ void annotateIclass(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool void annotateIso15693(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize); void annotateTopaz(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize); void annotateLegic(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize); -void annotateFelica(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize); +void annotateFelica(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool is_response); void annotateIso7816(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool is_response); void annotateCalypso(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool is_response); void annotateIso14443b(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool is_response); diff --git a/client/src/cmdtrace.c b/client/src/cmdtrace.c index 9a611dd4f..a2552277c 100644 --- a/client/src/cmdtrace.c +++ b/client/src/cmdtrace.c @@ -839,6 +839,9 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr case PROTO_HITAGS: annotateHitagS(explanation, sizeof(explanation), frame, (data_len * 8) - ((8 - parityBytes[0]) % 8), hdr->isResponse); break; + case FELICA: + annotateFelica(explanation, sizeof(explanation), frame, data_len, hdr->isResponse); + break; case PROTO_HITAGU: annotateHitagU(explanation, sizeof(explanation), frame, data_len, hdr->isResponse); break; @@ -872,9 +875,6 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr case ISO_15693: annotateIso15693(explanation, sizeof(explanation), frame, data_len); break; - case FELICA: - annotateFelica(explanation, sizeof(explanation), frame, data_len); - break; case LTO: annotateLTO(explanation, sizeof(explanation), frame, data_len); break;