]> git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlft55xx.c
First check in.
[proxmark3-svn] / client / cmdlft55xx.c
1 //-----------------------------------------------------------------------------
2 //
3 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
4 // at your option, any later version. See the LICENSE.txt file for the text of
5 // the license.
6 //-----------------------------------------------------------------------------
7 // Low frequency T55xx commands
8 //-----------------------------------------------------------------------------
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <inttypes.h>
13 #include "proxmark3.h"
14 #include "ui.h"
15 #include "graph.h"
16 #include "cmdmain.h"
17 #include "cmdparser.h"
18 #include "cmddata.h"
19 #include "cmdlf.h"
20 #include "cmdlft55xx.h"
21 #include "util.h"
22 #include "data.h"
23
24 #define LF_TRACE_BUFF_SIZE 16000
25 static int CmdHelp(const char *Cmd);
26
27
28 int CmdReadBlk(const char *Cmd)
29 {
30 //default to invalid block
31 int Block = -1;
32 UsbCommand c;
33
34 sscanf(Cmd, "%d", &Block);
35
36 if ((Block > 7) | (Block < 0)) {
37 PrintAndLog("Block must be between 0 and 7");
38 return 1;
39 }
40
41 PrintAndLog(" Reading page 0 block : %d", Block);
42
43 // this command fills up BigBuff
44 //
45 c.cmd = CMD_T55XX_READ_BLOCK;
46 c.d.asBytes[0] = 0x00;
47 c.arg[0] = 0;
48 c.arg[1] = Block;
49 c.arg[2] = 0;
50 SendCommand(&c);
51 WaitForResponse(CMD_ACK, NULL);
52
53 uint8_t data[LF_TRACE_BUFF_SIZE];
54 memset(data, 0x00, LF_TRACE_BUFF_SIZE);
55
56 GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,3560); //3560 -- should be offset..
57 WaitForResponseTimeout(CMD_ACK,NULL, 1500);
58
59 for (int j = 0; j < LF_TRACE_BUFF_SIZE; j++) {
60 GraphBuffer[j] = ((int)data[j]) - 128;
61 }
62 GraphTraceLen = LF_TRACE_BUFF_SIZE;
63
64 // BiDirectional
65 CmdDirectionalThreshold("70 -60");
66
67 // Askdemod
68 Cmdaskdemod("1");
69
70 uint8_t bits[1000];
71 uint8_t * bitstream = bits;
72 uint8_t len = 0;
73 len = manchester_decode(data, LF_TRACE_BUFF_SIZE, bitstream);
74 if ( len > 0 )
75 PrintPaddedManchester(bitstream, len, 32);
76
77 return 0;
78 }
79
80
81 int CmdReadBlkPWD(const char *Cmd)
82 {
83 int Block = -1; //default to invalid block
84 int Password = 0xFFFFFFFF; //default to blank Block 7
85 UsbCommand c;
86
87 sscanf(Cmd, "%d %x", &Block, &Password);
88
89 if ((Block > 7) | (Block < 0)) {
90 PrintAndLog("Block must be between 0 and 7");
91 return 1;
92 }
93
94 PrintAndLog("Reading page 0 block %d pwd %08X", Block, Password);
95
96 c.cmd = CMD_T55XX_READ_BLOCK;
97 c.d.asBytes[0] = 0x1; //Password mode
98 c.arg[0] = 0;
99 c.arg[1] = Block;
100 c.arg[2] = Password;
101 SendCommand(&c);
102 WaitForResponse(CMD_ACK, NULL);
103
104 uint8_t data[LF_TRACE_BUFF_SIZE];
105 memset(data, 0x00, LF_TRACE_BUFF_SIZE);
106
107 GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,3560); //3560 -- should be offset..
108 WaitForResponseTimeout(CMD_ACK,NULL, 1500);
109
110 for (int j = 0; j < LF_TRACE_BUFF_SIZE; j++) {
111 GraphBuffer[j] = ((int)data[j]) - 128;
112 }
113 GraphTraceLen = LF_TRACE_BUFF_SIZE;
114
115 // BiDirectional
116 CmdDirectionalThreshold("70 -60");
117
118 // Askdemod
119 Cmdaskdemod("1");
120
121 uint8_t bits[1000];
122 uint8_t len = 0;
123 len = manchester_decode(data, LF_TRACE_BUFF_SIZE, bits);
124 if ( len > 0 )
125 PrintPaddedManchester(bits, len, 32);
126
127 return 0;
128 }
129
130
131 int CmdWriteBlk(const char *Cmd)
132 {
133 int Block = 8; //default to invalid block
134 int Data = 0xFFFFFFFF; //default to blank Block
135 UsbCommand c;
136
137 sscanf(Cmd, "%x %d", &Data, &Block);
138
139 if (Block > 7) {
140 PrintAndLog("Block must be between 0 and 7");
141 return 1;
142 }
143
144 PrintAndLog("Writting block %d with data %08X", Block, Data);
145
146 c.cmd = CMD_T55XX_WRITE_BLOCK;
147 c.d.asBytes[0] = 0x0; //Normal mode
148 c.arg[0] = Data;
149 c.arg[1] = Block;
150 c.arg[2] = 0;
151 SendCommand(&c);
152 return 0;
153 }
154
155 int CmdWriteBlkPWD(const char *Cmd)
156 {
157 int Block = 8; //default to invalid block
158 int Data = 0xFFFFFFFF; //default to blank Block
159 int Password = 0xFFFFFFFF; //default to blank Block 7
160 UsbCommand c;
161
162 sscanf(Cmd, "%x %d %x", &Data, &Block, &Password);
163
164 if (Block > 7) {
165 PrintAndLog("Block must be between 0 and 7");
166 return 1;
167 }
168
169 PrintAndLog("Writting block %d with data %08X and password %08X", Block, Data, Password);
170
171 c.cmd = CMD_T55XX_WRITE_BLOCK;
172 c.d.asBytes[0] = 0x1; //Password mode
173 c.arg[0] = Data;
174 c.arg[1] = Block;
175 c.arg[2] = Password;
176 SendCommand(&c);
177 return 0;
178 }
179
180 int CmdReadTrace(const char *Cmd)
181 {
182 PrintAndLog(" Reading page 1 - tracedata");
183
184 UsbCommand c = {CMD_T55XX_READ_TRACE, {0, 0, 0}};
185 SendCommand(&c);
186 WaitForResponse(CMD_ACK, NULL);
187
188 uint8_t data[LF_TRACE_BUFF_SIZE];
189 memset(data, 0x00, LF_TRACE_BUFF_SIZE);
190
191 GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,3560); //3560 -- should be offset..
192 WaitForResponseTimeout(CMD_ACK,NULL, 1500);
193
194 for (int j = 0; j < LF_TRACE_BUFF_SIZE; j++) {
195 GraphBuffer[j] = ((int)data[j]) - 128;
196 }
197 GraphTraceLen = LF_TRACE_BUFF_SIZE;
198
199 // BiDirectional
200 CmdDirectionalThreshold("70 -60");
201
202 // Askdemod
203 Cmdaskdemod("1");
204
205 uint8_t bits[512];
206 uint8_t len = 0;
207 len = manchester_decode(data,LF_TRACE_BUFF_SIZE,bits);
208 if ( len > 0 )
209 PrintPaddedManchester(bits, len, 64);
210
211 return 0;
212 }
213
214 static command_t CommandTable[] =
215 {
216 {"help", CmdHelp, 1, "This help"},
217 {"readblock", CmdReadBlk, 1, "<Block> -- Read T55xx block data (page 0)"},
218 {"readblockPWD", CmdReadBlkPWD, 1, "<Block> <Password> -- Read T55xx block data in password mode(page 0)"},
219 {"writeblock", CmdWriteBlk, 1, "<Data> <Block> -- Write T55xx block data (page 0)"},
220 {"writeblockPWD", CmdWriteBlkPWD, 1, "<Data> <Block> <Password> -- Write T55xx block data in password mode(page 0)"},
221 {"readtrace", CmdReadTrace, 1, "Read T55xx traceability data (page 1)"},
222 {NULL, NULL, 0, NULL}
223 };
224
225 int CmdLFT55XX(const char *Cmd)
226 {
227 CmdsParse(CommandTable, Cmd);
228 return 0;
229 }
230
231 int CmdHelp(const char *Cmd)
232 {
233 CmdsHelp(CommandTable);
234 return 0;
235 }
Impressum, Datenschutz