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