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