]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/cmdhf14a.c
/client/Makefile: Output object files to the obj subdir.
[proxmark3-svn] / client / cmdhf14a.c
CommitLineData
7fe9b0b7 1#include <stdio.h>
590f8ff9 2#include <stdlib.h>
7fe9b0b7 3#include <string.h>
4#include "iso14443crc.h"
5#include "data.h"
6#include "proxusb.h"
7#include "ui.h"
8#include "cmdparser.h"
9#include "cmdhf14a.h"
10
11static int CmdHelp(const char *Cmd);
12
13int CmdHF14AList(const char *Cmd)
14{
15 uint8_t got[1920];
16 GetFromBigBuf(got, sizeof(got));
17
18 PrintAndLog("recorded activity:");
19 PrintAndLog(" ETU :rssi: who bytes");
20 PrintAndLog("---------+----+----+-----------");
21
22 int i = 0;
23 int prev = -1;
24
25 for (;;) {
26 if(i >= 1900) {
27 break;
28 }
29
30 bool isResponse;
31 int timestamp = *((uint32_t *)(got+i));
32 if (timestamp & 0x80000000) {
33 timestamp &= 0x7fffffff;
34 isResponse = 1;
35 } else {
36 isResponse = 0;
37 }
38
39 int metric = 0;
40 int parityBits = *((uint32_t *)(got+i+4));
41 // 4 bytes of additional information...
42 // maximum of 32 additional parity bit information
43 //
44 // TODO:
45 // at each quarter bit period we can send power level (16 levels)
46 // or each half bit period in 256 levels.
47
48
49 int len = got[i+8];
50
51 if (len > 100) {
52 break;
53 }
54 if (i + len >= 1900) {
55 break;
56 }
57
58 uint8_t *frame = (got+i+9);
59
60 // Break and stick with current result if buffer was not completely full
61 if (frame[0] == 0x44 && frame[1] == 0x44 && frame[3] == 0x44) { break; }
62
63 char line[1000] = "";
64 int j;
65 for (j = 0; j < len; j++) {
66 int oddparity = 0x01;
67 int k;
68
69 for (k=0;k<8;k++) {
70 oddparity ^= (((frame[j] & 0xFF) >> k) & 0x01);
71 }
72
73 //if((parityBits >> (len - j - 1)) & 0x01) {
74 if (isResponse && (oddparity != ((parityBits >> (len - j - 1)) & 0x01))) {
75 sprintf(line+(j*4), "%02x! ", frame[j]);
76 }
77 else {
78 sprintf(line+(j*4), "%02x ", frame[j]);
79 }
80 }
81
82 char *crc;
83 crc = "";
84 if (len > 2) {
85 uint8_t b1, b2;
86 for (j = 0; j < (len - 1); j++) {
87 // gives problems... search for the reason..
88 /*if(frame[j] == 0xAA) {
89 switch(frame[j+1]) {
90 case 0x01:
91 crc = "[1] Two drops close after each other";
92 break;
93 case 0x02:
94 crc = "[2] Potential SOC with a drop in second half of bitperiod";
95 break;
96 case 0x03:
97 crc = "[3] Segment Z after segment X is not possible";
98 break;
99 case 0x04:
100 crc = "[4] Parity bit of a fully received byte was wrong";
101 break;
102 default:
103 crc = "[?] Unknown error";
104 break;
105 }
106 break;
107 }*/
108 }
109
110 if (strlen(crc)==0) {
111 ComputeCrc14443(CRC_14443_A, frame, len-2, &b1, &b2);
112 if (b1 != frame[len-2] || b2 != frame[len-1]) {
113 crc = (isResponse & (len < 6)) ? "" : " !crc";
114 } else {
115 crc = "";
116 }
117 }
118 } else {
119 crc = ""; // SHORT
120 }
121
122 char metricString[100];
123 if (isResponse) {
124 sprintf(metricString, "%3d", metric);
125 } else {
126 strcpy(metricString, " ");
127 }
128
129 PrintAndLog(" +%7d: %s: %s %s %s",
130 (prev < 0 ? 0 : (timestamp - prev)),
131 metricString,
132 (isResponse ? "TAG" : " "), line, crc);
133
134 prev = timestamp;
135 i += (len + 9);
136 }
137 return 0;
138}
139
140int CmdHF14AMifare(const char *Cmd)
141{
142 UsbCommand c = {CMD_READER_MIFARE, {strtol(Cmd, NULL, 0), 0, 0}};
143 SendCommand(&c);
144 return 0;
145}
146
147int CmdHF14AReader(const char *Cmd)
148{
149 UsbCommand c = {CMD_READER_ISO_14443a, {strtol(Cmd, NULL, 0), 0, 0}};
150 SendCommand(&c);
151 return 0;
152}
153
154// ## simulate iso14443a tag
155// ## greg - added ability to specify tag UID
156int CmdHF14ASim(const char *Cmd)
157{
158
159 unsigned int hi = 0, lo = 0;
160 int n = 0, i = 0;
161 while (sscanf(&Cmd[i++], "%1x", &n ) == 1) {
162 hi= (hi << 4) | (lo >> 28);
163 lo= (lo << 4) | (n & 0xf);
164 }
165
166 // c.arg should be set to *Cmd or convert *Cmd to the correct format for a uid
167 UsbCommand c = {CMD_SIMULATE_TAG_ISO_14443a, {hi, lo, 0}};
168 PrintAndLog("Emulating 14443A TAG with UID %x%16x", hi, lo);
169 SendCommand(&c);
170 return 0;
171}
172
173int CmdHF14ASnoop(const char *Cmd)
174{
175 UsbCommand c = {CMD_SNOOP_ISO_14443a};
176 SendCommand(&c);
177 return 0;
178}
179
180static command_t CommandTable[] =
181{
182 {"help", CmdHelp, 1, "This help"},
183 {"list", CmdHF14AList, 0, "List ISO 14443a history"},
184 {"mifare", CmdHF14AMifare, 0, "Read out sector 0 parity error messages"},
185 {"reader", CmdHF14AReader, 0, "Act like an ISO14443 Type A reader"},
186 {"sim", CmdHF14ASim, 0, "<UID> -- Fake ISO 14443a tag"},
187 {"snoop", CmdHF14ASnoop, 0, "Eavesdrop ISO 14443 Type A"},
188 {NULL, NULL, 0, NULL}
189};
190
191int CmdHF14A(const char *Cmd)
192{
193 CmdsParse(CommandTable, Cmd);
194 return 0;
195}
196
197int CmdHelp(const char *Cmd)
198{
199 CmdsHelp(CommandTable);
200 return 0;
201}
Impressum, Datenschutz