4 #include "iso14443crc.h"
11 static int CmdHelp(const char *Cmd
);
13 int CmdHF14AList(const char *Cmd
)
16 GetFromBigBuf(got
, sizeof(got
));
18 PrintAndLog("recorded activity:");
19 PrintAndLog(" ETU :rssi: who bytes");
20 PrintAndLog("---------+----+----+-----------");
31 int timestamp
= *((uint32_t *)(got
+i
));
32 if (timestamp
& 0x80000000) {
33 timestamp
&= 0x7fffffff;
40 int parityBits
= *((uint32_t *)(got
+i
+4));
41 // 4 bytes of additional information...
42 // maximum of 32 additional parity bit information
45 // at each quarter bit period we can send power level (16 levels)
46 // or each half bit period in 256 levels.
54 if (i
+ len
>= 1900) {
58 uint8_t *frame
= (got
+i
+9);
60 // Break and stick with current result if buffer was not completely full
61 if (frame
[0] == 0x44 && frame
[1] == 0x44 && frame
[3] == 0x44) { break; }
65 for (j
= 0; j
< len
; j
++) {
70 oddparity
^= (((frame
[j
] & 0xFF) >> k
) & 0x01);
73 //if((parityBits >> (len - j - 1)) & 0x01) {
74 if (isResponse
&& (oddparity
!= ((parityBits
>> (len
- j
- 1)) & 0x01))) {
75 sprintf(line
+(j
*4), "%02x! ", frame
[j
]);
78 sprintf(line
+(j
*4), "%02x ", frame
[j
]);
86 for (j
= 0; j
< (len
- 1); j
++) {
87 // gives problems... search for the reason..
88 /*if(frame[j] == 0xAA) {
91 crc = "[1] Two drops close after each other";
94 crc = "[2] Potential SOC with a drop in second half of bitperiod";
97 crc = "[3] Segment Z after segment X is not possible";
100 crc = "[4] Parity bit of a fully received byte was wrong";
103 crc = "[?] Unknown error";
110 if (strlen(crc
)==0) {
111 ComputeCrc14443(CRC_14443_A
, frame
, len
-2, &b1
, &b2
);
112 if (b1
!= frame
[len
-2] || b2
!= frame
[len
-1]) {
113 crc
= (isResponse
& (len
< 6)) ? "" : " !crc";
122 char metricString
[100];
124 sprintf(metricString
, "%3d", metric
);
126 strcpy(metricString
, " ");
129 PrintAndLog(" +%7d: %s: %s %s %s",
130 (prev
< 0 ? 0 : (timestamp
- prev
)),
132 (isResponse
? "TAG" : " "), line
, crc
);
140 int CmdHF14AMifare(const char *Cmd
)
142 UsbCommand c
= {CMD_READER_MIFARE
, {strtol(Cmd
, NULL
, 0), 0, 0}};
147 int CmdHF14AReader(const char *Cmd
)
149 UsbCommand c
= {CMD_READER_ISO_14443a
, {strtol(Cmd
, NULL
, 0), 0, 0}};
154 // ## simulate iso14443a tag
155 // ## greg - added ability to specify tag UID
156 int CmdHF14ASim(const char *Cmd
)
159 unsigned int hi
= 0, lo
= 0;
161 while (sscanf(&Cmd
[i
++], "%1x", &n
) == 1) {
162 hi
= (hi
<< 4) | (lo
>> 28);
163 lo
= (lo
<< 4) | (n
& 0xf);
166 // c.arg should be set to *Cmd or convert *Cmd to the correct format for a uid
167 UsbCommand c
= {CMD_SIMULATE_TAG_ISO_14443a
, {hi
, lo
, 0}};
168 PrintAndLog("Emulating 14443A TAG with UID %x%16x", hi
, lo
);
173 int CmdHF14ASnoop(const char *Cmd
)
175 UsbCommand c
= {CMD_SNOOP_ISO_14443a
};
180 static command_t CommandTable
[] =
182 {"help", CmdHelp
, 1, "This help"},
183 {"list", CmdHF14AList
, 0, "List ISO 14443a history"},
184 {"mifare", CmdHF14AMifare
, 0, "Read out sector 0 parity error messages"},
185 {"reader", CmdHF14AReader
, 0, "Act like an ISO14443 Type A reader"},
186 {"sim", CmdHF14ASim
, 0, "<UID> -- Fake ISO 14443a tag"},
187 {"snoop", CmdHF14ASnoop
, 0, "Eavesdrop ISO 14443 Type A"},
188 {NULL
, NULL
, 0, NULL
}
191 int CmdHF14A(const char *Cmd
)
193 CmdsParse(CommandTable
, Cmd
);
197 int CmdHelp(const char *Cmd
)
199 CmdsHelp(CommandTable
);