3 #include "iso14443crc.h"
10 static int CmdHelp(const char *Cmd
);
12 int CmdHF14AList(const char *Cmd
)
15 GetFromBigBuf(got
, sizeof(got
));
17 PrintAndLog("recorded activity:");
18 PrintAndLog(" ETU :rssi: who bytes");
19 PrintAndLog("---------+----+----+-----------");
30 int timestamp
= *((uint32_t *)(got
+i
));
31 if (timestamp
& 0x80000000) {
32 timestamp
&= 0x7fffffff;
39 int parityBits
= *((uint32_t *)(got
+i
+4));
40 // 4 bytes of additional information...
41 // maximum of 32 additional parity bit information
44 // at each quarter bit period we can send power level (16 levels)
45 // or each half bit period in 256 levels.
53 if (i
+ len
>= 1900) {
57 uint8_t *frame
= (got
+i
+9);
59 // Break and stick with current result if buffer was not completely full
60 if (frame
[0] == 0x44 && frame
[1] == 0x44 && frame
[3] == 0x44) { break; }
64 for (j
= 0; j
< len
; j
++) {
69 oddparity
^= (((frame
[j
] & 0xFF) >> k
) & 0x01);
72 //if((parityBits >> (len - j - 1)) & 0x01) {
73 if (isResponse
&& (oddparity
!= ((parityBits
>> (len
- j
- 1)) & 0x01))) {
74 sprintf(line
+(j
*4), "%02x! ", frame
[j
]);
77 sprintf(line
+(j
*4), "%02x ", frame
[j
]);
85 for (j
= 0; j
< (len
- 1); j
++) {
86 // gives problems... search for the reason..
87 /*if(frame[j] == 0xAA) {
90 crc = "[1] Two drops close after each other";
93 crc = "[2] Potential SOC with a drop in second half of bitperiod";
96 crc = "[3] Segment Z after segment X is not possible";
99 crc = "[4] Parity bit of a fully received byte was wrong";
102 crc = "[?] Unknown error";
109 if (strlen(crc
)==0) {
110 ComputeCrc14443(CRC_14443_A
, frame
, len
-2, &b1
, &b2
);
111 if (b1
!= frame
[len
-2] || b2
!= frame
[len
-1]) {
112 crc
= (isResponse
& (len
< 6)) ? "" : " !crc";
121 char metricString
[100];
123 sprintf(metricString
, "%3d", metric
);
125 strcpy(metricString
, " ");
128 PrintAndLog(" +%7d: %s: %s %s %s",
129 (prev
< 0 ? 0 : (timestamp
- prev
)),
131 (isResponse
? "TAG" : " "), line
, crc
);
139 int CmdHF14AMifare(const char *Cmd
)
141 UsbCommand c
= {CMD_READER_MIFARE
, {strtol(Cmd
, NULL
, 0), 0, 0}};
146 int CmdHF14AReader(const char *Cmd
)
148 UsbCommand c
= {CMD_READER_ISO_14443a
, {strtol(Cmd
, NULL
, 0), 0, 0}};
153 // ## simulate iso14443a tag
154 // ## greg - added ability to specify tag UID
155 int CmdHF14ASim(const char *Cmd
)
158 unsigned int hi
= 0, lo
= 0;
160 while (sscanf(&Cmd
[i
++], "%1x", &n
) == 1) {
161 hi
= (hi
<< 4) | (lo
>> 28);
162 lo
= (lo
<< 4) | (n
& 0xf);
165 // c.arg should be set to *Cmd or convert *Cmd to the correct format for a uid
166 UsbCommand c
= {CMD_SIMULATE_TAG_ISO_14443a
, {hi
, lo
, 0}};
167 PrintAndLog("Emulating 14443A TAG with UID %x%16x", hi
, lo
);
172 int CmdHF14ASnoop(const char *Cmd
)
174 UsbCommand c
= {CMD_SNOOP_ISO_14443a
};
179 static command_t CommandTable
[] =
181 {"help", CmdHelp
, 1, "This help"},
182 {"list", CmdHF14AList
, 0, "List ISO 14443a history"},
183 {"mifare", CmdHF14AMifare
, 0, "Read out sector 0 parity error messages"},
184 {"reader", CmdHF14AReader
, 0, "Act like an ISO14443 Type A reader"},
185 {"sim", CmdHF14ASim
, 0, "<UID> -- Fake ISO 14443a tag"},
186 {"snoop", CmdHF14ASnoop
, 0, "Eavesdrop ISO 14443 Type A"},
187 {NULL
, NULL
, 0, NULL
}
190 int CmdHF14A(const char *Cmd
)
192 CmdsParse(CommandTable
, Cmd
);
196 int CmdHelp(const char *Cmd
)
198 CmdsHelp(CommandTable
);