]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhflist.c
fix 'hf iclass reader'
[proxmark3-svn] / client / cmdhflist.c
index db3e5287371b03b7e9d9482581007e838caca28e..29d10d924025e9d09d3488e24689583fe01ea684 100644 (file)
@@ -24,8 +24,8 @@
 #include "parity.h"
 #include "protocols.h"
 #include "crapto1/crapto1.h"
-#include "mifarehost.h"
-#include "mifaredefault.h"
+#include "mifare/mifarehost.h"
+#include "mifare/mifaredefault.h"
 #include "usb_cmd.h"
 #include "pcsc.h"
 
@@ -213,30 +213,30 @@ uint8_t iclass_CRC_check(bool isResponse, uint8_t* data, uint8_t len)
 }
 
 
-void annotateIclass(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
-{
+void annotateIclass(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize) {
        switch(cmd[0])
        {
-       case ICLASS_CMD_ACTALL:      snprintf(exp,size,"ACTALL"); break;
-       case ICLASS_CMD_READ_OR_IDENTIFY:{
-               if(cmdsize > 1){
+       case ICLASS_CMD_ACTALL:      snprintf(exp, size, "ACTALL"); break;
+       case ICLASS_CMD_READ_OR_IDENTIFY: {
+               if (cmdsize > 1){
                        snprintf(exp,size,"READ(%d)",cmd[1]);
-               }else{
+               } else {
                        snprintf(exp,size,"IDENTIFY");
                }
                break;
        }
-       case ICLASS_CMD_SELECT:      snprintf(exp,size,"SELECT"); break;
-       case ICLASS_CMD_PAGESEL:     snprintf(exp,size,"PAGESEL(%d)", cmd[1]); break;
-       case ICLASS_CMD_READCHECK_KC:snprintf(exp,size,"READCHECK[Kc](%d)", cmd[1]); break;
-       case ICLASS_CMD_READCHECK_KD:snprintf(exp,size,"READCHECK[Kd](%d)", cmd[1]); break;
-       case ICLASS_CMD_CHECK:       snprintf(exp,size,"CHECK"); break;
-       case ICLASS_CMD_DETECT:      snprintf(exp,size,"DETECT"); break;
-       case ICLASS_CMD_HALT:        snprintf(exp,size,"HALT"); break;
-       case ICLASS_CMD_UPDATE:      snprintf(exp,size,"UPDATE(%d)",cmd[1]); break;
-       case ICLASS_CMD_ACT:         snprintf(exp,size,"ACT"); break;
-       case ICLASS_CMD_READ4:       snprintf(exp,size,"READ4(%d)",cmd[1]); break;
-       default:                     snprintf(exp,size,"?"); break;
+       case ICLASS_CMD_SELECT:       snprintf(exp,size, "SELECT"); break;
+       case ICLASS_CMD_PAGESEL:      snprintf(exp,size, "PAGESEL(%d)", cmd[1]); break;
+       case ICLASS_CMD_READCHECK_KC: snprintf(exp,size, "READCHECK[Kc](%d)", cmd[1]); break;
+       case ICLASS_CMD_READCHECK_KD: snprintf(exp,size, "READCHECK[Kd](%d)", cmd[1]); break;
+       case ICLASS_CMD_CHECK_KC:
+       case ICLASS_CMD_CHECK_KD:     snprintf(exp,size, "CHECK"); break;
+       case ICLASS_CMD_DETECT:       snprintf(exp,size, "DETECT"); break;
+       case ICLASS_CMD_HALT:         snprintf(exp,size, "HALT"); break;
+       case ICLASS_CMD_UPDATE:       snprintf(exp,size, "UPDATE(%d)",cmd[1]); break;
+       case ICLASS_CMD_ACT:          snprintf(exp,size, "ACT"); break;
+       case ICLASS_CMD_READ4:        snprintf(exp,size, "READ4(%d)",cmd[1]); break;
+       default:                      snprintf(exp,size, "?"); break;
        }
        return;
 }
@@ -337,7 +337,7 @@ void annotateIso14443_4(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize){
        else {
                int pos = 1;
                switch (cmd[0] & 0x0c) {
-                       case 0x08: // CID following 
+                       case 0x08: // CID following
                        case 0x04: // NAD following
                                pos = 2;
                                break;
@@ -415,8 +415,8 @@ void annotateIso14443a(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
        case ISO14443A_CMD_REQA:
                snprintf(exp,size,"REQA");
                break;
-       case ISO14443A_CMD_READBLOCK:   snprintf(exp,size,"READBLOCK(%d)",cmd[1]); break;
-       case ISO14443A_CMD_WRITEBLOCK:  snprintf(exp,size,"WRITEBLOCK(%d)",cmd[1]); break;
+       case MIFARE_CMD_READBLOCK:   snprintf(exp,size,"READBLOCK(%d)",cmd[1]); break;
+       case MIFARE_CMD_WRITEBLOCK:  snprintf(exp,size,"WRITEBLOCK(%d)",cmd[1]); break;
        case ISO14443A_CMD_HALT:
                snprintf(exp,size,"HALT");
                MifareAuthState = masNone;
@@ -901,6 +901,11 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui
                }
        }
 
+       // adjust for different time scales
+       if (protocol == ICLASS || protocol == ISO_15693) {
+               duration *= 32;
+       }
+
        //Check the CRC status
        uint8_t crcStatus = 2;
 
@@ -937,10 +942,10 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui
        char line[16][110];
 
        for (int j = 0; j < data_len && j/16 < 16; j++) {
-
                uint8_t parityBits = parityBytes[j>>3];
                if (protocol != ISO_14443B
                        && protocol != ISO_15693
+                       && protocol != ICLASS
                        && protocol != ISO_7816_4
                        && (isResponse || protocol == ISO_14443A)
                        && (oddparity8(frame[j]) != ((parityBits >> (7-(j&0x0007))) & 0x01))) {
@@ -948,12 +953,10 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui
                } else {
                        snprintf(line[j/16]+(( j % 16) * 4), 110, " %02x ", frame[j]);
                }
-
        }
 
        if (markCRCBytes) {
-               if(crcStatus == 0 || crcStatus == 1)
-               {//CRC-command
+               if (crcStatus == 0 || crcStatus == 1) { //CRC-command
                        char *pos1 = line[(data_len-2)/16]+(((data_len-2) % 16) * 4);
                        (*pos1) = '[';
                        char *pos2 = line[(data_len)/16]+(((data_len) % 16) * 4);
@@ -961,8 +964,19 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui
                }
        }
 
+       // mark short bytes (less than 8 Bit + Parity)
+       if (protocol == ISO_14443A || protocol == PROTO_MIFARE) {
+               if (duration < 128 * (9 * data_len)) {
+                       line[(data_len-1)/16][((data_len-1)%16) * 4 + 3] = '\'';
+               }
+       }
+
        if (data_len == 0) {
-               sprintf(line[0]," <empty trace - possible error>");
+               if (protocol == ICLASS && duration == 2048) {
+                       sprintf(line[0], " <SOF>");
+               } else {
+                       sprintf(line[0], " <empty trace - possible error>");
+               }
        }
 
        //--- Draw the CRC column
@@ -973,8 +987,7 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui
        if (protocol == PROTO_MIFARE)
                annotateMifare(explanation, sizeof(explanation), frame, data_len, parityBytes, parity_len, isResponse);
 
-       if(!isResponse)
-       {
+       if (!isResponse) {
                switch(protocol) {
                        case ICLASS:      annotateIclass(explanation,sizeof(explanation),frame,data_len); break;
                        case ISO_14443A:  annotateIso14443a(explanation,sizeof(explanation),frame,data_len); break;
@@ -990,7 +1003,7 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui
        int num_lines = MIN((data_len - 1)/16 + 1, 16);
        for (int j = 0; j < num_lines ; j++) {
                if (j == 0) {
-                       PrintAndLog(" %10d | %10d | %s |%-64s | %s| %s",
+                       PrintAndLog(" %10" PRIu32 " | %10" PRIu32 " | %s |%-64s | %s| %s",
                                (timestamp - first_timestamp),
                                (EndOfTransmissionTimestamp - first_timestamp),
                                (isResponse ? "Tag" : "Rdr"),
@@ -1022,6 +1035,7 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui
 
        if (showWaitCycles && !isResponse && next_record_is_response(tracepos, trace)) {
                uint32_t next_timestamp = *((uint32_t *)(trace + tracepos));
+
                PrintAndLog(" %10d | %10d | %s | fdt (Frame Delay Time): %d",
                        (EndOfTransmissionTimestamp - first_timestamp),
                        (next_timestamp - first_timestamp),
@@ -1222,7 +1236,7 @@ int CmdHFList(const char *Cmd)
                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("      Start |        End | Src | Data (! denotes parity error, ' denotes short bytes)            | CRC | Annotation         |");
                PrintAndLog("------------|------------|-----|-----------------------------------------------------------------|-----|--------------------|");
 
                ClearAuthData();
Impressum, Datenschutz