1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
8 // High frequency ISO14443A commands
9 //-----------------------------------------------------------------------------
14 #include "iso14443crc.h"
18 #include "cmdparser.h"
21 static int CmdHelp(const char *Cmd
);
23 int CmdHF14AList(const char *Cmd
)
26 GetFromBigBuf(got
, sizeof(got
));
28 PrintAndLog("recorded activity:");
29 PrintAndLog(" ETU :rssi: who bytes");
30 PrintAndLog("---------+----+----+-----------");
41 int timestamp
= *((uint32_t *)(got
+i
));
42 if (timestamp
& 0x80000000) {
43 timestamp
&= 0x7fffffff;
50 int parityBits
= *((uint32_t *)(got
+i
+4));
51 // 4 bytes of additional information...
52 // maximum of 32 additional parity bit information
55 // at each quarter bit period we can send power level (16 levels)
56 // or each half bit period in 256 levels.
64 if (i
+ len
>= 1900) {
68 uint8_t *frame
= (got
+i
+9);
70 // Break and stick with current result if buffer was not completely full
71 if (frame
[0] == 0x44 && frame
[1] == 0x44 && frame
[3] == 0x44) { break; }
75 for (j
= 0; j
< len
; j
++) {
80 oddparity
^= (((frame
[j
] & 0xFF) >> k
) & 0x01);
83 //if((parityBits >> (len - j - 1)) & 0x01) {
84 if (isResponse
&& (oddparity
!= ((parityBits
>> (len
- j
- 1)) & 0x01))) {
85 sprintf(line
+(j
*4), "%02x! ", frame
[j
]);
88 sprintf(line
+(j
*4), "%02x ", frame
[j
]);
96 for (j
= 0; j
< (len
- 1); j
++) {
97 // gives problems... search for the reason..
98 /*if(frame[j] == 0xAA) {
101 crc = "[1] Two drops close after each other";
104 crc = "[2] Potential SOC with a drop in second half of bitperiod";
107 crc = "[3] Segment Z after segment X is not possible";
110 crc = "[4] Parity bit of a fully received byte was wrong";
113 crc = "[?] Unknown error";
120 if (strlen(crc
)==0) {
121 ComputeCrc14443(CRC_14443_A
, frame
, len
-2, &b1
, &b2
);
122 if (b1
!= frame
[len
-2] || b2
!= frame
[len
-1]) {
123 crc
= (isResponse
& (len
< 6)) ? "" : " !crc";
132 char metricString
[100];
134 sprintf(metricString
, "%3d", metric
);
136 strcpy(metricString
, " ");
139 PrintAndLog(" +%7d: %s: %s %s %s",
140 (prev
< 0 ? 0 : (timestamp
- prev
)),
142 (isResponse
? "TAG" : " "), line
, crc
);
150 int CmdHF14AMifare(const char *Cmd
)
152 UsbCommand c
= {CMD_READER_MIFARE
, {strtol(Cmd
, NULL
, 0), 0, 0}};
157 int CmdHF14AReader(const char *Cmd
)
159 UsbCommand c
= {CMD_READER_ISO_14443a
, {strtol(Cmd
, NULL
, 0), 0, 0}};
164 // ## simulate iso14443a tag
165 // ## greg - added ability to specify tag UID
166 int CmdHF14ASim(const char *Cmd
)
169 unsigned int hi
= 0, lo
= 0;
171 while (sscanf(&Cmd
[i
++], "%1x", &n
) == 1) {
172 hi
= (hi
<< 4) | (lo
>> 28);
173 lo
= (lo
<< 4) | (n
& 0xf);
176 // c.arg should be set to *Cmd or convert *Cmd to the correct format for a uid
177 UsbCommand c
= {CMD_SIMULATE_TAG_ISO_14443a
, {hi
, lo
, 0}};
178 PrintAndLog("Emulating 14443A TAG with UID %x%16x", hi
, lo
);
183 int CmdHF14ASnoop(const char *Cmd
)
185 UsbCommand c
= {CMD_SNOOP_ISO_14443a
};
190 static command_t CommandTable
[] =
192 {"help", CmdHelp
, 1, "This help"},
193 {"list", CmdHF14AList
, 0, "List ISO 14443a history"},
194 {"mifare", CmdHF14AMifare
, 0, "Read out sector 0 parity error messages"},
195 {"reader", CmdHF14AReader
, 0, "Act like an ISO14443 Type A reader"},
196 {"sim", CmdHF14ASim
, 0, "<UID> -- Fake ISO 14443a tag"},
197 {"snoop", CmdHF14ASnoop
, 0, "Eavesdrop ISO 14443 Type A"},
198 {NULL
, NULL
, 0, NULL
}
201 int CmdHF14A(const char *Cmd
)
203 CmdsParse(CommandTable
, Cmd
);
207 int CmdHelp(const char *Cmd
)
209 CmdsHelp(CommandTable
);