Skip to content

Commit 53ee5d6

Browse files
committed
Improve output format of hf felica rdbl; fix wrong response struct format
1 parent 9b59204 commit 53ee5d6

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

client/src/cmdhffelica.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,11 @@ static void clear_and_send_command(uint8_t flags, uint16_t datalen, uint8_t *dat
495495
/**
496496
* Prints read-without-encryption response.
497497
* @param rd_noCry_resp Response frame.
498+
* @param block_index Optional explicit block index (UINT16_MAX to use tag value)
498499
*/
499-
static void print_rd_plain_response(felica_read_without_encryption_response_t *rd_noCry_resp) {
500+
static void print_rd_plain_response(felica_read_without_encryption_response_t *rd_noCry_resp, uint16_t block_index) {
501+
502+
uint16_t display_block = block_index;
500503

501504
if (rd_noCry_resp->status_flags.status_flag1[0] == 00 &&
502505
rd_noCry_resp->status_flags.status_flag2[0] == 00) {
@@ -506,15 +509,14 @@ static void print_rd_plain_response(felica_read_without_encryption_response_t *r
506509
char bl_data[256];
507510
strncpy(bl_data, temp, sizeof(bl_data) - 1);
508511

509-
char bl_element_number[4];
510-
temp = sprint_hex(rd_noCry_resp->block_element_number, sizeof(rd_noCry_resp->block_element_number));
511-
strncpy(bl_element_number, temp, sizeof(bl_element_number) - 1);
512512

513-
PrintAndLogEx(INFO, " %s | %s ", bl_element_number, bl_data);
513+
PrintAndLogEx(INFO, " %04X | %s ", display_block, bl_data);
514514
} else {
515-
PrintAndLogEx(SUCCESS, "IDm... %s", sprint_hex_inrow(rd_noCry_resp->frame_response.IDm, sizeof(rd_noCry_resp->frame_response.IDm)));
516-
PrintAndLogEx(SUCCESS, " Status flag 1... %s", sprint_hex(rd_noCry_resp->status_flags.status_flag1, sizeof(rd_noCry_resp->status_flags.status_flag1)));
517-
PrintAndLogEx(SUCCESS, " Status flag 2... %s", sprint_hex(rd_noCry_resp->status_flags.status_flag1, sizeof(rd_noCry_resp->status_flags.status_flag1)));
515+
char sf1[8];
516+
char sf2[8];
517+
snprintf(sf1, sizeof(sf1), "%02X", rd_noCry_resp->status_flags.status_flag1[0]);
518+
snprintf(sf2, sizeof(sf2), "%02X", rd_noCry_resp->status_flags.status_flag2[0]);
519+
PrintAndLogEx(INFO, " %04X | Status flag 1... %s; Status flag 2... %s", display_block, sf1, sf2);
518520
}
519521
}
520522

@@ -563,7 +565,12 @@ int send_rd_plain(uint8_t flags, uint16_t datalen, uint8_t *data, bool verbose,
563565
return PM3_ERFTRANS;
564566
} else {
565567
memcpy(rd_noCry_resp, (felica_read_without_encryption_response_t *)resp.data.asBytes, sizeof(felica_read_without_encryption_response_t));
566-
rd_noCry_resp->block_element_number[0] = data[15];
568+
if (rd_noCry_resp->frame_response.cmd_code[0] != 0x07) {
569+
PrintAndLogEx(FAILED, "Bad response cmd 0x%02X @ 0x%04X.",
570+
rd_noCry_resp->frame_response.cmd_code[0], 0x00);
571+
PrintAndLogEx(INFO, "This is either a normal signal issue, or an issue caused by wrong parameter. Please try again.");
572+
return PM3_ERFTRANS;
573+
}
567574
return PM3_SUCCESS;
568575
}
569576
}
@@ -1313,17 +1320,15 @@ static int CmdHFFelicaReadPlain(const char *Cmd) {
13131320
data[15] = i;
13141321
felica_read_without_encryption_response_t rd_noCry_resp;
13151322
if ((send_rd_plain(flags, datalen, data, 0, &rd_noCry_resp) == PM3_SUCCESS)) {
1316-
if (rd_noCry_resp.status_flags.status_flag1[0] == 0 && rd_noCry_resp.status_flags.status_flag2[0] == 0) {
1317-
print_rd_plain_response(&rd_noCry_resp);
1318-
}
1323+
print_rd_plain_response(&rd_noCry_resp, i);
13191324
} else {
13201325
break;
13211326
}
13221327
}
13231328
} else {
13241329
felica_read_without_encryption_response_t rd_noCry_resp;
13251330
if (send_rd_plain(flags, datalen, data, 1, &rd_noCry_resp) == PM3_SUCCESS) {
1326-
print_rd_plain_response(&rd_noCry_resp);
1331+
print_rd_plain_response(&rd_noCry_resp, bnlen ? bn[0] : 0);
13271332
}
13281333
}
13291334
return PM3_SUCCESS;
@@ -1792,7 +1797,7 @@ static int CmdHFFelicaDump(const char *Cmd) {
17921797
felica_read_without_encryption_response_t rd_noCry_resp;
17931798
if ((send_rd_plain(flags, block_datalen, data_block_dump, 0, &rd_noCry_resp) == PM3_SUCCESS)) {
17941799
if (rd_noCry_resp.status_flags.status_flag1[0] == 0 && rd_noCry_resp.status_flags.status_flag2[0] == 0) {
1795-
print_rd_plain_response(&rd_noCry_resp);
1800+
print_rd_plain_response(&rd_noCry_resp, i);
17961801
} else {
17971802
break; // no more blocks to read
17981803
}

include/iso18.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ typedef struct {
8888
felica_status_flags_t status_flags;
8989
uint8_t number_of_block[1];
9090
uint8_t block_data[16];
91-
uint8_t block_element_number[1];
9291
} PACKED felica_read_without_encryption_response_t;
9392

9493
typedef struct {

0 commit comments

Comments
 (0)