]>
git.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 static command_t CommandTable
[] =
175 {"help", CmdHelp
, 1, "This help"},
176 {"list", CmdHFiClassList
, 0, "List iClass history"},
177 {"snoop", CmdHFiClassSnoop
, 0, "Eavesdrop iClass communication"},
178 {NULL
, NULL
, 0, NULL
}
181 int CmdHFiClass(const char *Cmd
)
183 CmdsParse(CommandTable
, Cmd
);
187 int CmdHelp(const char *Cmd
)
189 CmdsHelp(CommandTable
);