]> git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlft55xx.c
a002bf3446ab3a9344b9bea082efad6ba2989ecc
[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 memset(bitstream, 0x00, sizeof(bits));
73
74 manchester_decode(GraphBuffer, LF_TRACE_BUFF_SIZE, bitstream);
75
76 return 0;
77 }
78
79
80 int CmdReadBlkPWD(const char *Cmd)
81 {
82 int Block = -1; //default to invalid block
83 int Password = 0xFFFFFFFF; //default to blank Block 7
84 UsbCommand c;
85
86 sscanf(Cmd, "%d %x", &Block, &Password);
87
88 if ((Block > 7) | (Block < 0)) {
89 PrintAndLog("Block must be between 0 and 7");
90 return 1;
91 }
92
93 PrintAndLog("Reading page 0 block %d pwd %08X", Block, Password);
94
95 c.cmd = CMD_T55XX_READ_BLOCK;
96 c.d.asBytes[0] = 0x1; //Password mode
97 c.arg[0] = 0;
98 c.arg[1] = Block;
99 c.arg[2] = Password;
100 SendCommand(&c);
101 WaitForResponse(CMD_ACK, NULL);
102
103 uint8_t data[LF_TRACE_BUFF_SIZE];
104 memset(data, 0x00, LF_TRACE_BUFF_SIZE);
105
106 GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,3560); //3560 -- should be offset..
107 WaitForResponseTimeout(CMD_ACK,NULL, 1500);
108
109 for (int j = 0; j < LF_TRACE_BUFF_SIZE; j++) {
110 GraphBuffer[j] = ((int)data[j]) - 128;
111 }
112 GraphTraceLen = LF_TRACE_BUFF_SIZE;
113
114 // BiDirectional
115 //CmdDirectionalThreshold("70 -60");
116
117 // Askdemod
118 //Cmdaskdemod("1");
119
120 uint8_t bits[1000];
121 uint8_t * bitstream = bits;
122 memset(bitstream, 0x00, sizeof(bits));
123
124 manchester_decode(GraphBuffer, LF_TRACE_BUFF_SIZE, bitstream);
125 return 0;
126 }
127
128
129 int CmdWriteBlk(const char *Cmd)
130 {
131 int Block = 8; //default to invalid block
132 int Data = 0xFFFFFFFF; //default to blank Block
133 UsbCommand c;
134
135 sscanf(Cmd, "%x %d", &Data, &Block);
136
137 if (Block > 7) {
138 PrintAndLog("Block must be between 0 and 7");
139 return 1;
140 }
141
142 PrintAndLog("Writting block %d with data %08X", Block, Data);
143
144 c.cmd = CMD_T55XX_WRITE_BLOCK;
145 c.d.asBytes[0] = 0x0; //Normal mode
146 c.arg[0] = Data;
147 c.arg[1] = Block;
148 c.arg[2] = 0;
149 SendCommand(&c);
150 return 0;
151 }
152
153 int CmdWriteBlkPWD(const char *Cmd)
154 {
155 int Block = 8; //default to invalid block
156 int Data = 0xFFFFFFFF; //default to blank Block
157 int Password = 0xFFFFFFFF; //default to blank Block 7
158 UsbCommand c;
159
160 sscanf(Cmd, "%x %d %x", &Data, &Block, &Password);
161
162 if (Block > 7) {
163 PrintAndLog("Block must be between 0 and 7");
164 return 1;
165 }
166
167 PrintAndLog("Writting block %d with data %08X and password %08X", Block, Data, Password);
168
169 c.cmd = CMD_T55XX_WRITE_BLOCK;
170 c.d.asBytes[0] = 0x1; //Password mode
171 c.arg[0] = Data;
172 c.arg[1] = Block;
173 c.arg[2] = Password;
174 SendCommand(&c);
175 return 0;
176 }
177
178 int CmdReadTrace(const char *Cmd)
179 {
180 PrintAndLog(" Reading page 1 - tracedata");
181
182 UsbCommand c = {CMD_T55XX_READ_TRACE, {0, 0, 0}};
183 SendCommand(&c);
184 WaitForResponse(CMD_ACK, NULL);
185
186 uint8_t data[LF_TRACE_BUFF_SIZE];
187 memset(data, 0x00, LF_TRACE_BUFF_SIZE);
188
189 GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,3560); //3560 -- should be offset..
190 WaitForResponseTimeout(CMD_ACK,NULL, 1500);
191
192 for (int j = 0; j < LF_TRACE_BUFF_SIZE; j++) {
193 GraphBuffer[j] = ((int)data[j]) - 128;
194 }
195 GraphTraceLen = LF_TRACE_BUFF_SIZE;
196
197 // BiDirectional
198 //CmdDirectionalThreshold("70 -60");
199
200 // Askdemod
201 //Cmdaskdemod("1");
202
203
204 uint8_t bits[1000];
205 uint8_t * bitstream = bits;
206 memset(bitstream, 0x00, sizeof(bits));
207
208 manchester_decode(GraphBuffer, LF_TRACE_BUFF_SIZE, bitstream);
209
210 return 0;
211 }
212
213 static command_t CommandTable[] =
214 {
215 {"help", CmdHelp, 1, "This help"},
216 {"rd", CmdReadBlk, 0, "<Block> -- Read T55xx block data (page 0)"},
217 {"rdPWD", CmdReadBlkPWD, 0, "<Block> <Password> -- Read T55xx block data in password mode(page 0)"},
218 {"wr", CmdWriteBlk, 0, "<Data> <Block> -- Write T55xx block data (page 0)"},
219 {"wrPWD", CmdWriteBlkPWD, 0, "<Data> <Block> <Password> -- Write T55xx block data in password mode(page 0)"},
220 {"trace", CmdReadTrace, 0, "Read T55xx traceability data (page 1)"},
221 {NULL, NULL, 0, NULL}
222 };
223
224 int CmdLFT55XX(const char *Cmd)
225 {
226 CmdsParse(CommandTable, Cmd);
227 return 0;
228 }
229
230 int CmdHelp(const char *Cmd)
231 {
232 CmdsHelp(CommandTable);
233 return 0;
234 }
Impressum, Datenschutz