- }
- //--- Draw the CRC column
- bool crcError = false;
-
- if (data_len > 2) {
- uint8_t b1, b2;
- if(iclass)
- {
- if(!isResponse && data_len == 4 ) {
- // Rough guess that this is a command from the reader
- // For iClass the command byte is not part of the CRC
- ComputeCrc14443(CRC_ICLASS, &frame[1], data_len-3, &b1, &b2);
- }
- else {
- // For other data.. CRC might not be applicable (UPDATE commands etc.)
- ComputeCrc14443(CRC_ICLASS, frame, data_len-2, &b1, &b2);
- }
-
- if (b1 != frame[data_len-2] || b2 != frame[data_len-1]) {
- crcError = true;
- }
-
- }else{//Iso 14443a
-
- ComputeCrc14443(CRC_14443_A, frame, data_len-2, &b1, &b2);
-
- if (b1 != frame[data_len-2] || b2 != frame[data_len-1]) {
- if(!(isResponse & (data_len < 6)))
- {
- crcError = true;
- }
- }
- }
-
- }
- char *crc = crcError ? "!crc" :" ";
-
- EndOfTransmissionTimestamp = timestamp + duration;
-
- if(!isResponse)
- {
- if(iclass) annotateIclass(explanation,sizeof(explanation),frame,data_len);
- else annotateIso14443a(explanation,sizeof(explanation),frame,data_len);
- }
-
- int num_lines = (data_len - 1)/16 + 1;
- for (int j = 0; j < num_lines; j++) {
- if (j == 0) {
- PrintAndLog(" %9d | %9d | %s | %-64s| %s| %s",
- (timestamp - first_timestamp),
- (EndOfTransmissionTimestamp - first_timestamp),
- (isResponse ? "Tag" : "Rdr"),
- line[j],
- (j == num_lines-1) ? crc : " ",
- (j == num_lines-1) ? explanation : "");
- } else {
- PrintAndLog(" | | | %-64s| %s| %s",
- line[j],
- (j == num_lines-1)?crc:" ",
- (j == num_lines-1) ? explanation : "");
- }
- }
-
- bool next_isResponse = *((uint16_t *)(trace + tracepos + 6)) & 0x8000;
-
- if (showWaitCycles && !isResponse && next_isResponse) {
- uint32_t next_timestamp = *((uint32_t *)(trace + tracepos));
- if (next_timestamp != 0x44444444) {
- PrintAndLog(" %9d | %9d | %s | fdt (Frame Delay Time): %d",
- (EndOfTransmissionTimestamp - first_timestamp),
- (next_timestamp - first_timestamp),
- " ",
- (next_timestamp - EndOfTransmissionTimestamp));
- }
- }
- return tracepos;
-}
-
-int CmdHFList(const char *Cmd)
-{
- bool showWaitCycles = false;
- char type[40] = {0};
- int tlen = param_getstr(Cmd,0,type);
- char param = param_getchar(Cmd, 1);
- bool errors = false;
- bool iclass = false;
- //Validate params
- if(tlen == 0 || (strcmp(type, "iclass") != 0 && strcmp(type,"14a") != 0))
- {
- errors = true;
- }
- if(param == 'h' || (param !=0 && param != 'f'))
- {
- errors = true;
- }
-
- if (errors) {
- PrintAndLog("List protocol data in trace buffer.");
- PrintAndLog("Usage: hf list [14a|iclass] [f]");
- PrintAndLog(" - interpret data as iso14443a communications");
- PrintAndLog(" iclass - interpret data as iclass communications");
- PrintAndLog(" f - show frame delay times as well");
- PrintAndLog("");
- PrintAndLog("example: hf list 14a f");
- PrintAndLog("example: hf list iclass");
- return 0;
- }
- if(strcmp(type, "iclass") == 0)
- {
- iclass = true;
- }
-
- if (param == 'f') {
- showWaitCycles = true;
- }
-
-
- uint8_t trace[TRACE_SIZE];
- uint16_t tracepos = 0;
- GetFromBigBuf(trace, TRACE_SIZE, 0);
- WaitForResponse(CMD_ACK, NULL);
-
- PrintAndLog("Recorded Activity");
- PrintAndLog("");
- PrintAndLog("Start = Start of Start Bit, End = End of last modulation. Src = Source of Transfer");
- PrintAndLog("iso14443a - All times are in carrier periods (1/13.56Mhz)");
- PrintAndLog("iClass - Timings are not as accurate");
- PrintAndLog("");
- PrintAndLog(" Start | End | Src | Data (! denotes parity error) | CRC | Annotation |");
- PrintAndLog("-----------|-----------|-----|-----------------------------------------------------------------|-----|--------------------|");
-
- while(tracepos < TRACE_SIZE)
- {
- tracepos = printTraceLine(tracepos, trace, iclass, showWaitCycles);