]>
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"
24 static int CmdHelp(const char *Cmd
);
26 int CmdHFiClassList(const char *Cmd
)
29 GetFromBigBuf(got
,sizeof(got
),0);
31 PrintAndLog("recorded activity:");
32 PrintAndLog(" ETU :rssi: who bytes");
33 PrintAndLog("---------+----+----+-----------");
44 int timestamp
= *((uint32_t *)(got
+i
));
45 if (timestamp
& 0x80000000) {
46 timestamp
&= 0x7fffffff;
53 int parityBits
= *((uint32_t *)(got
+i
+4));
54 // 4 bytes of additional information...
55 // maximum of 32 additional parity bit information
58 // at each quarter bit period we can send power level (16 levels)
59 // or each half bit period in 256 levels.
67 if (i
+ len
>= 1900) {
71 uint8_t *frame
= (got
+i
+9);
73 // Break and stick with current result if buffer was not completely full
74 if (frame
[0] == 0x44 && frame
[1] == 0x44 && frame
[3] == 0x44) { break; }
78 for (j
= 0; j
< len
; j
++) {
83 oddparity
^= (((frame
[j
] & 0xFF) >> k
) & 0x01);
86 //if((parityBits >> (len - j - 1)) & 0x01) {
87 if (isResponse
&& (oddparity
!= ((parityBits
>> (len
- j
- 1)) & 0x01))) {
88 sprintf(line
+(j
*4), "%02x! ", frame
[j
]);
91 sprintf(line
+(j
*4), "%02x ", frame
[j
]);
99 for (j
= 0; j
< (len
- 1); j
++) {
100 // gives problems... search for the reason..
101 /*if(frame[j] == 0xAA) {
104 crc = "[1] Two drops close after each other";
107 crc = "[2] Potential SOC with a drop in second half of bitperiod";
110 crc = "[3] Segment Z after segment X is not possible";
113 crc = "[4] Parity bit of a fully received byte was wrong";
116 crc = "[?] Unknown error";
123 if (strlen(crc
)==0) {
124 if(!isResponse
&& len
== 4) {
125 // Rough guess that this is a command from the reader
126 // For iClass the command byte is not part of the CRC
127 ComputeCrc14443(CRC_ICLASS
, &frame
[1], len
-3, &b1
, &b2
);
130 // For other data.. CRC might not be applicable (UPDATE commands etc.)
131 ComputeCrc14443(CRC_ICLASS
, frame
, len
-2, &b1
, &b2
);
133 //printf("%1x %1x",(unsigned)b1,(unsigned)b2);
134 if (b1
!= frame
[len
-2] || b2
!= frame
[len
-1]) {
135 crc
= (isResponse
& (len
< 8)) ? "" : " !crc";
144 char metricString
[100];
146 sprintf(metricString
, "%3d", metric
);
148 strcpy(metricString
, " ");
151 PrintAndLog(" +%7d: %s: %s %s %s",
152 (prev
< 0 ? 0 : (timestamp
- prev
)),
154 (isResponse
? "TAG" : " "), line
, crc
);
162 /*void iso14a_set_timeout(uint32_t timeout) {
163 UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_SET_TIMEOUT, 0, timeout}};
167 int CmdHFiClassSnoop(const char *Cmd
)
169 UsbCommand c
= {CMD_SNOOP_ICLASS
};
174 int CmdHFiClassSim(const char *Cmd
)
177 uint8_t CSN
[8] = {0, 0, 0, 0, 0, 0, 0, 0};
180 PrintAndLog("Usage: hf iclass sim <sim type> <CSN (16 hex symbols)>");
181 PrintAndLog(" sample: hf iclass sim 0 031FEC8AF7FF12E0");
185 simType
= param_get8(Cmd
, 0);
186 if (param_gethex(Cmd
, 1, CSN
, 16)) {
187 PrintAndLog("A CSN should consist of 16 HEX symbols");
190 PrintAndLog("--simtype:%02x csn:%s", simType
, sprint_hex(CSN
, 8));
192 UsbCommand c
= {CMD_SIMULATE_TAG_ICLASS
, {simType
}};
193 memcpy(c
.d
.asBytes
, CSN
, 8);
196 /*UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);
198 uint8_t isOK = resp->arg[0] & 0xff;
199 PrintAndLog("isOk:%02x", isOK);
201 PrintAndLog("Command execute timeout");
207 int CmdHFiClassReader(const char *Cmd
)
209 uint8_t readerType
= 0;
212 PrintAndLog("Usage: hf iclass reader <reader type>");
213 PrintAndLog(" sample: hf iclass reader 0");
217 readerType
= param_get8(Cmd
, 0);
218 PrintAndLog("--readertype:%02x", readerType
);
220 UsbCommand c
= {CMD_READER_ICLASS
, {readerType
}};
221 //memcpy(c.d.asBytes, CSN, 8);
224 /*UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);
226 uint8_t isOK = resp->arg[0] & 0xff;
227 PrintAndLog("isOk:%02x", isOK);
229 PrintAndLog("Command execute timeout");
235 static command_t CommandTable
[] =
237 {"help", CmdHelp
, 1, "This help"},
238 {"list", CmdHFiClassList
, 0, "List iClass history"},
239 {"snoop", CmdHFiClassSnoop
, 0, "Eavesdrop iClass communication"},
240 {"sim", CmdHFiClassSim
, 0, "Simulate iClass tag"},
241 {"reader", CmdHFiClassReader
, 0, "Read an iClass tag"},
242 {NULL
, NULL
, 0, NULL
}
245 int CmdHFiClass(const char *Cmd
)
247 CmdsParse(CommandTable
, Cmd
);
251 int CmdHelp(const char *Cmd
)
253 CmdsHelp(CommandTable
);