]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhficlass.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>, Hagen Fritsch
3 // Copyright (C) 2011 Gerhard de Koning Gans
5 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
6 // at your option, any later version. See the LICENSE.txt file for the text of
8 //-----------------------------------------------------------------------------
9 // High frequency iClass commands
10 //-----------------------------------------------------------------------------
15 #include "iso14443crc.h" // Can also be used for iClass, using 0xE012 as CRC-type
19 #include "cmdparser.h"
20 #include "cmdhficlass.h"
23 static int CmdHelp(const char *Cmd
);
25 int CmdHFiClassList(const char *Cmd
)
28 GetFromBigBuf(got
, sizeof(got
));
30 PrintAndLog("recorded activity:");
31 PrintAndLog(" ETU :rssi: who bytes");
32 PrintAndLog("---------+----+----+-----------");
43 int timestamp
= *((uint32_t *)(got
+i
));
44 if (timestamp
& 0x80000000) {
45 timestamp
&= 0x7fffffff;
52 int parityBits
= *((uint32_t *)(got
+i
+4));
53 // 4 bytes of additional information...
54 // maximum of 32 additional parity bit information
57 // at each quarter bit period we can send power level (16 levels)
58 // or each half bit period in 256 levels.
66 if (i
+ len
>= 1900) {
70 uint8_t *frame
= (got
+i
+9);
72 // Break and stick with current result if buffer was not completely full
73 if (frame
[0] == 0x44 && frame
[1] == 0x44 && frame
[3] == 0x44) { break; }
77 for (j
= 0; j
< len
; j
++) {
82 oddparity
^= (((frame
[j
] & 0xFF) >> k
) & 0x01);
85 //if((parityBits >> (len - j - 1)) & 0x01) {
86 if (isResponse
&& (oddparity
!= ((parityBits
>> (len
- j
- 1)) & 0x01))) {
87 sprintf(line
+(j
*4), "%02x! ", frame
[j
]);
90 sprintf(line
+(j
*4), "%02x ", frame
[j
]);
98 for (j
= 0; j
< (len
- 1); j
++) {
99 // gives problems... search for the reason..
100 /*if(frame[j] == 0xAA) {
103 crc = "[1] Two drops close after each other";
106 crc = "[2] Potential SOC with a drop in second half of bitperiod";
109 crc = "[3] Segment Z after segment X is not possible";
112 crc = "[4] Parity bit of a fully received byte was wrong";
115 crc = "[?] Unknown error";
122 if (strlen(crc
)==0) {
123 if(!isResponse
&& len
== 4) {
124 // Rough guess that this is a command from the reader
125 // For iClass the command byte is not part of the CRC
126 ComputeCrc14443(CRC_ICLASS
, &frame
[1], len
-3, &b1
, &b2
);
129 // For other data.. CRC might not be applicable (UPDATE commands etc.)
130 ComputeCrc14443(CRC_ICLASS
, frame
, len
-2, &b1
, &b2
);
132 //printf("%1x %1x",(unsigned)b1,(unsigned)b2);
133 if (b1
!= frame
[len
-2] || b2
!= frame
[len
-1]) {
134 crc
= (isResponse
& (len
< 8)) ? "" : " !crc";
143 char metricString
[100];
145 sprintf(metricString
, "%3d", metric
);
147 strcpy(metricString
, " ");
150 PrintAndLog(" +%7d: %s: %s %s %s",
151 (prev
< 0 ? 0 : (timestamp
- prev
)),
153 (isResponse
? "TAG" : " "), line
, crc
);
161 /*void iso14a_set_timeout(uint32_t timeout) {
162 UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_SET_TIMEOUT, 0, timeout}};
166 int CmdHFiClassSnoop(const char *Cmd
)
168 UsbCommand c
= {CMD_SNOOP_ICLASS
};
173 int CmdHFiClassSim(const char *Cmd
)
176 uint8_t CSN
[8] = {0, 0, 0, 0, 0, 0, 0, 0};
179 PrintAndLog("Usage: hf iclass sim <sim type> <CSN (16 hex symbols)>");
180 PrintAndLog(" sample: hf iclass sim 0 031FEC8AF7FF12E0");
184 simType
= param_get8(Cmd
, 0);
185 if (param_gethex(Cmd
, 1, CSN
, 16)) {
186 PrintAndLog("A CSN should consist of 16 HEX symbols");
189 PrintAndLog("--simtype:%02x csn:%s", simType
, sprint_hex(CSN
, 8));
191 UsbCommand c
= {CMD_SIMULATE_TAG_ICLASS
, {simType
}};
192 memcpy(c
.d
.asBytes
, CSN
, 8);
195 /*UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);
197 uint8_t isOK = resp->arg[0] & 0xff;
198 PrintAndLog("isOk:%02x", isOK);
200 PrintAndLog("Command execute timeout");
206 int CmdHFiClassReader(const char *Cmd
)
208 uint8_t readerType
= 0;
211 PrintAndLog("Usage: hf iclass reader <reader type>");
212 PrintAndLog(" sample: hf iclass reader 0");
216 readerType
= param_get8(Cmd
, 0);
217 PrintAndLog("--readertype:%02x", readerType
);
219 UsbCommand c
= {CMD_READER_ICLASS
, {readerType
}};
220 //memcpy(c.d.asBytes, CSN, 8);
223 /*UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);
225 uint8_t isOK = resp->arg[0] & 0xff;
226 PrintAndLog("isOk:%02x", isOK);
228 PrintAndLog("Command execute timeout");
234 static command_t CommandTable
[] =
236 {"help", CmdHelp
, 1, "This help"},
237 {"list", CmdHFiClassList
, 0, "List iClass history"},
238 {"snoop", CmdHFiClassSnoop
, 0, "Eavesdrop iClass communication"},
239 {"sim", CmdHFiClassSim
, 0, "Simulate iClass tag"},
240 {"reader", CmdHFiClassReader
, 0, "Read an iClass tag"},
241 {NULL
, NULL
, 0, NULL
}
244 int CmdHFiClass(const char *Cmd
)
246 CmdsParse(CommandTable
, Cmd
);
250 int CmdHelp(const char *Cmd
)
252 CmdsHelp(CommandTable
);